VIM:打开Python文件时缩进更改

时间:2010-09-04 19:55:29

标签: vim

当我打开Python文件时,我的缩进会发生变化。我有以下vimrc设置:

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首选项。

3 个答案:

答案 0 :(得分:3)

我添加了@ dash-tom-bang的答案:shiftwidth和expandtab选项都是缓冲区的本地选项。无需添加任何自动命令,只需使用set更改所有setlocal语句,这样就不会更改默认值。

答案 1 :(得分:1)

其中包含* .py的au行正在改变您的设置。值得注意的是,

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

打开HTML文件时,您需要“撤消”这些设置。只需添加一些可用于* .html的autocmds来设置noexpandtab并将你的shiftwidth设置回8。

答案 2 :(得分:0)

我建议将http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc保存在某个地方并从.vimrc中获取。这应该可以省去麻烦。

编辑:哦,显然,这已经是你正在做的事情了!

相关问题