在 Vim 7.3 中有选择地禁用特定文件类型的'filetype plugin indent'



我有vim 7.3,默认情况下设置为Ubuntu 11.04。我的.virc看起来如下:

set nocompatible
set autoindent
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
filetype plugin indent on
let g:omni_sql_no_default_maps = 1 " Stops Omni from grabbing left/right keys
" syntax, colorscheme and status line directives omitted.

如何针对不同的文件类型(例如php、phtml、rb(选择性地禁用此缩进?

到目前为止,我已经尝试了autocmd FileType php filetype plugin indent off和一些变体,但运气还不太好。

(删除filetype plugin ...行会产生所需的行为,但显然会影响所有文件类型,而不仅仅是少数文件类型。(

王子关于autocmd的建议对我不起作用

filetype plugin on
autocmd BufRead,BufNewFile * filetype indent off
autocmd BufRead,BufNewFile *.py filetype indent on

为python文件选择性地启用filetype indent on。还有set ai非常酷,因为它适用于将缩进作为回退的文件。

请注意,禁用filetype indent可能不是您想要的:

    :filetype indent off

[…]这实际上加载了文件"runtimepath"中的"indoff.vim"。这将禁用文件的自动缩进您打开。它将在已打开的文件中继续工作。重置要禁用的"autoindent"、"cindent"、"smartindent"和/或"indentexpr"在打开的文件中缩进。

如果你想,就像这个在线帮助建议的那样,禁用某些文件类型的缩进选项,你可以把它放在你的.vimrc:中

filetype plugin indent on
au filetype php,phtml,rb call DisableIndent()
function! DisableIndent()
        set autoindent&
        set cindent&
        set smartindent&
        set indentexpr&
endfunction

此外,请参阅在线帮助(例如:help autoindent(,确保了解您正在关闭的这些选项。

filetype indent on命令所做的只是源$VIMRUNTIME/indent.vim,它本身打开文件类型并调用单个$VIMRUNTIME/indent/[type].vim。因此,您可以修改默认的indent.vim以忽略某些文件类型(或者将此文件的修改版本保存在.vim/intent.vim本地(

如果你对此不满意,你可以尝试在你的vimrc中单独设置插件/缩进行为:

filetype plugin on
au FileType c,vim,lisp filetype indent on

(当然还要添加相关的文件类型(。这对我有用。

最新更新