2010-09-04 79 views
0

當我打開Python文件時,我的縮進會發生變化。我有以下vimrc設置:VIM:打開Python文件時縮進會發生變化

set number 
colorscheme wombat256mod 
set guifont=Consolas\ 11 
set linespace=2 
filetype on 
filetype plugin on 

au BufRead,BufNewFile *py,*pyw,*.c,*.h set tabstop=4 
au BufRead,BufNewFile *.py,*pyw set shiftwidth=4 
au BufRead,BufNewFile *.py,*.pyw set expandtab 
fu Select_c_style() 
    if search('^\t', 'n', 150) 
    set shiftwidth=8 
    set noexpandtab 
    el 
    set shiftwidth=4 
    set expandtab 
    en 
endf 
au BufRead,BufNewFile *.c,*.h call Select_c_style() 
au BufRead,BufNewFile Makefile* set noexpandtab 
highlight BadWhitespace ctermbg=red guibg=red 
au BufRead,BufNewFile *.py,*.pyw match BadWhitespace /^\t\+/ 
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/ 
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h set textwidth=79 
au BufRead,BufNewFile *.c,*.h set formatoptions-=c formatoptions-=o formatoptions-=r 
au BufNewFile *.py,*.pyw,*.c,*.h set fileformat=unix 
let python_highlight_all=1 
syntax on 
filetype indent on 
set autoindent 

任何人看到的東西,可以導致它?

例如,我打開一個* .html文件的縮進是一個選項卡。但是,一旦我打開任何Python文件並返回到html文件,縮進切換到python偏好設置。

+0

你有一行_ton_行設置縮進 - 爲什麼你把它們放在那裏,如果你不知道他們做了什麼? – alternative 2010-09-04 20:18:23

回答

1

帶有* .py的au行是什麼改變你的設置。值得注意的是,

au BufRead,BufNewFile *.py,*pyw set shiftwidth=4 
au BufRead,BufNewFile *.py,*.pyw set expandtab 

當打開HTML文件時,您需要「撤銷」這些設置。只需添加一些可以在* .html上工作的autocmds來設置noexpandtab並將您的shiftwidth設置回8.

0

我建議在某個地方保存http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc並從.vimrc中獲取它。這應該可以避免麻煩。

編輯:哦,很明顯,這已經是你在做的事!

+0

我不明白你能解釋當我打開一個Python文件時,你的回答將如何阻止我的縮進變化嗎? – Pickels 2010-09-04 20:01:58

3

我對@ dash-tom-bang的答案有一個補充:對於緩衝區,shiftwidth和expandtab選項都是本地的。無需添加任何自動命令,只需將所有set語句更改爲setlocal即可,因此它不會更改默認值。

+0

非常感謝! – Pickels 2010-09-05 10:54:39

+0

感謝這個ZyX,因爲我一直在努力解決類似的問題(特別是我的格式爲.txt文件泄漏到其他文件緩衝區)。 – 2010-09-07 17:00:17

相關問題