2013-10-20 46 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的環境,這不僅能幫助你設置你的縮進,製表符&空間正常,還爲你安裝幾個重要的插件。

相關問題