在Vim 7.3中针对特定文件类型选择性地禁用"filetype插件缩进"

Rob*_*ard 6 vim indentation

我有vim 7.3,默认情况下使用Ubuntu 11.04提供的设置.我的.vimrc如下所示:

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.
Run Code Online (Sandbox Code Playgroud)

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

到目前为止,我已经尝试autocmd FileType php filetype plugin indent off了一些变种,但我还没有多少运气.

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

cli*_*ime 6

王子关于 autocmd 的建议对我不起作用。这会:

filetype plugin on
autocmd BufRead,BufNewFile * filetype indent off
autocmd BufRead,BufNewFile *.py filetype indent on
Run Code Online (Sandbox Code Playgroud)

filetype indent on选择地启用 python 文件。它也很酷,set ai因为它适用于带有缩进作为后备的文件。


etu*_*rdu 5

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

    :filetype indent off
Run Code Online (Sandbox Code Playgroud)

[...]这实际上在'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
Run Code Online (Sandbox Code Playgroud)

此外,请务必通过咨询在线帮助(例如:help autoindent)了解您关闭的这些选项.