有选择地禁用“文件类型插件缩进”对于 Vim 7.3 中的特定文件类型
我有 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.
如何选择性地为不同文件类型(例如 php、phtml、rb)禁用此缩进?
到目前为止,我已经尝试了 autocmd FileType php filetype plugin indent off
和一些变体,但我还没有太多运气。
(删除 filetype plugin ...
行会产生所需的行为,但显然会影响所有文件类型,而不仅仅是少数。)
I have vim 7.3, with the setup that's provided with Ubuntu 11.04 by default. My .vimrc looks like the following:
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.
How do I selectively disable this indentation for different filetypes (eg. php, phtml, rb)?
So far I've tried autocmd FileType php filetype plugin indent off
and a few variants, but I haven't had much luck yet.
(Removing the filetype plugin ...
line produces the desired behaviour, but obviously affects all filetypes instead of just a few.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
王子关于 autocmd 的建议对我不起作用。其作用是:
有选择地为 python 文件启用
filetype indent on
。还设置 ai
非常酷,因为它适用于将缩进关闭作为后备的文件。The Prince's suggestion with autocmd does not work for me. This does:
Enables
filetype indent on
selectively for python files. It's pretty cool to have alsoset ai
because it works for files with indent off as a fallback.请注意,禁用
filetype indent
可能不是您想要的:如果您想要,就像此在线帮助所建议的那样,禁用某些文件类型的缩进选项,您可以将其放入
.vimrc
中:另外,请确保了解您要关闭的这些选项是什么通过查阅在线帮助(例如
:help autoindent
)。Note that disabling
filetype indent
is likely not what you want:If you want, just like suggested by this online help, to disable indenting options for some filetypes, you could put this in your
.vimrc
:Also, make sure to understand what these options you are turning off are by consulting the online help (e.g.
:help autoindent
).filetype indent on
命令所做的就是获取$VIMRUNTIME/indent.vim
的源代码,它本身会打开文件类型并调用单独的$VIMRUNTIME/indent/[type ].vim
。因此,您可以修改默认的 indent.vim 以忽略某些文件类型(或将该文件的修改版本保存在本地 .vim/indent.vim 中)。如果您对此不满意,可以尝试在 vimrc 中单独设置插件/缩进行为:(
当然还要添加相关的文件类型)。这对我有用。
All the
filetype indent on
command does is to source$VIMRUNTIME/indent.vim
, which itself switches on filetype and calls the individual$VIMRUNTIME/indent/[type].vim
. So you could modify the default indent.vim to ignore certain filetypes (or save a modified version of this file locally at .vim/indent.vim).If you are unhappy with that you could try setting the plugin/indent behaviour in your vimrc separately:
(and of course add the relevant filetypes). This works for me.