VIM:打开Python文件时缩进发生变化
当我打开Python文件时,缩进会发生变化。我有以下vimrc设置:VIM:打开Python文件时缩进发生变化,vim,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 B
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首选项 我建议在某个地方保存并从.vimrc中获取。这样可以省去麻烦
编辑:哦,很显然,你已经在做这些了 我建议在某个地方保存并从.vimrc中获取。这样可以省去麻烦
编辑:哦,很显然,你已经在做这些了 其中带有*.py的au线正在更改您的设置。值得注意的是
au BufRead,BufNewFile *.py,*pyw set shiftwidth=4
au BufRead,BufNewFile *.py,*.pyw set expandtab
打开HTML文件时,需要“撤消”这些设置。只需再添加几个在*.html上工作的autocmd,将noexpandtab设置为noexpandtab,并将shiftwidth设置回8。其中带有*.py的au行就是更改设置的原因。值得注意的是
au BufRead,BufNewFile *.py,*pyw set shiftwidth=4
au BufRead,BufNewFile *.py,*.pyw set expandtab
打开HTML文件时,需要“撤消”这些设置。只需再添加几个在*.html上工作的autocmd来设置noexpandtab,并将shiftwidth设置回8。我对@dash tom bang的答案有一个补充:shiftwidth和expandtab选项都是缓冲区的本地选项。无需添加任何自动命令,只需使用
setlocal
更改所有set
语句,这样它就不会更改默认值。我对@dash tom bang的答案进行了补充:shiftwidth和expandtab选项都是缓冲区的本地选项。无需添加任何自动命令,只需使用setlocal
更改所有set
语句即可,因此,它不会改变默认值。我不明白您能否解释一下,当我打开Python文件时,您的答案将如何停止我的缩进更改?我不明白您能否解释一下,当我打开Python文件时,您的答案将如何停止我的缩进更改?您有大量行设置缩进-如果需要,为什么要将它们放在那里不知道它们做了什么?你有很多行设置缩进-如果你不知道它们做了什么,为什么要把它们放在那里?感谢这个ZyX,因为我一直在努力解决类似的问题(特别是我的.txt文件格式泄漏到其他文件缓冲区)。感谢这个ZyX,因为我一直在努力解决一系列类似的问题(尤其是我的.txt文件格式泄漏到其他文件缓冲区)。