代码之家  ›  专栏  ›  技术社区  ›  Pickels

vim:打开python文件时缩进更改

vim
  •  0
  • Pickels  · 技术社区  · 14 年前

    当我打开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 回复  |  直到 14 年前
        1
  •  1
  •   dash-tom-bang    14 年前

    其中带有*.py的au行正在更改您的设置。尤其是,

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

    打开HTML文件时需要“撤消”这些设置。只需再添加几个在*.html上工作的autocmd就可以设置noexpandab,并将shiftwidth设置回8。

        2
  •  3
  •   ZyX    14 年前

    我在@dash tom bang的答案中增加了一个:shiftwidth和expandtab选项都是缓冲区的本地选项。不需要添加任何自动命令,只需全部更改 set 语句与 setlocal ,因此它不会更改默认值。

        3
  •  0
  •   0fnt    14 年前

    我建议你节约 http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc 在某个地方,并从.vimrc采购。这样可以省去麻烦。

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