VIM: Indentation changes when opening Python files
when I open Python files my indentation changes. I have the following vimrc settings:
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
Anybody see something that can cause it?
For example I open an *.html file the indentation is a tab. But once I opened any Python file and go back to the html file the indentation switches to python preferences.
I have an addition to @dash-tom-bang's answer: both shiftwidth and expandtab options are local to buffer. No need to add any autocommands, just change all set statements with setlocal, so it will not alter the defaults.
The au lines with *.py in them are what are changing your settings. Notably,
au BufRead,BufNewFile *.py,*pyw set shiftwidth=4
au BufRead,BufNewFile *.py,*.pyw set expandtab
You need to "undo" these settings when opening HTML files. Just add a few more autocmds that work on *.html to set noexpandtab and set your shiftwidth back to 8.
I would suggest saving http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc at some place and sourcing it from .vimrc. That should save hassles.
EDIT: Oh, well apparently, that's already something you're doing!
加载中,请稍侯......
精彩评论