2013-10-20 25 views
0

我知道这个问题最有可能被问及很多次,我已经在寻找一个解决方案,但是我发现相互冲突的答案并没有完全解决我的问题。设置vim与python很好地工作

我使用vim进行所有文本编辑,最近我开始使用Python,但我遇到了缩进问题。每当我选择正确的标签,并且vim中的所有内容都看起来不错时,我会收到编译错误,我将不得不去编辑emacs来检查错误的实际位置。

我已经看到一些.vimrc文件有配置来防止这个问题,但没有任何工作对我来说。

任何人都可以给我一些指导吗?

+0

可能想看看这个: http://stackoverflow.com/questions/1024435/howto-fix-python-indentation/1024463#1024463 –

回答

0

我使用的是Mac,这是建立在UNIX,这里是我的.vimrc:

set nocompatible "cannot remember, but necessary for something 
syntax on "syntax highlighting 

filetype plugin indent on 

au FileType htm setlocal expandtab shiftwidth=2 softtabstop=2 
au FileType html setlocal expandtab shiftwidth=2 softtabstop=2 
au FileType css setlocal expandtab shiftwidth=2 softtabstop=2 
au FileType javascript setlocal expandtab shiftwidth=2 softtabstop=2 
au FileType xml setlocal expandtab shiftwidth=2 softtabstop=2 
au FileType ruby setlocal expandtab shiftwidth=2 softtabstop=2 
au BufNewFile,BufRead *.ru set filetype=ruby 
au BufNewFile,BufRead *.slim set filetype=ruby 
au FileType cgi setlocal expandtab shiftwidth=2 softtabstop=2 

au FileType python setlocal expandtab shiftwidth=4 softtabstop=4 
au FileType perl setlocal expandtab shiftwidth=4 softtabstop=4 
au FileType php setlocal expandtab shiftwidth=4 softtabstop=4 
au FileType java setlocal expandtab shiftwidth=4 softtabstop=4 
au FileType cpp setlocal expandtab shiftwidth=4 softtabstop=4 

au BufNewFile,BufRead *.coffee set filetype=ruby 
au BufNewFile,BufRead *.jsp set filetype=html 

set textwidth=78 

蟒蛇相关的东西归结为:

set nocompatible "cannot remember, but necessary for something 
syntax on "syntax highlighting 

filetype plugin indent on 

au FileType python setlocal expandtab shiftwidth=4 softtabstop=4 

set textwidth=78 

我会得到编译错误,我将不得不去像 emacs这样的编辑器来检查错误的实际位置。

怎么回事?

+0

感谢您的答复。这似乎解决了这个问题。 该问题与标签有关。 Vim会显示适当的选项卡,但是当我进入emacs时,它会显示不正确的标签,并且我将不断需要在令人沮丧的编辑器之间切换。 – SlashTag

0

尝试下面的代码片段添加到您的.vimrc

autocmd FILETYPE python setlocal expandtab | setlocal shiftwidth=4 | 
    \setlocal softtabstop=4 | setlocal textwidth=78 | setlocal tabstop=4 
    \set smarttab | set smartindent 
0

另一种快速的方法是通过Maximum Awesuomespf13-vim 设置您的Vim的环境,这不仅能帮助你设置你的缩进,制表符&空间正常,还为你安装几个重要的插件。

相关问题