![](/img/trans.png)
[英]How do I set an autocmd in the vimrc to only run with specific filetypes?
[英]vimrc: execute multiple lines only for certain filetypes
我的 .vimrc 中有几行我只想用于某些文件类型(在我的例子中是 HTML)
目前看起来像
autocmd! FileType html set matchpairs+=<:>
autocmd! FileType html abb <div> <div><CR><\div><up><CR><TAB>
autocmd! FileType html abb <span> ...etc.
我想知道,我是否真的需要每次都重新输入第一部分,或者类似的东西
autocmd! FileType html[
set matchpairs+=<:>
abb <div> <div><CR><\div><up><CR><TAB>
abb <span> ...etc.
]
Vim 的“文件类型”机制已经很好地处理了您的需求,因此您不必使用特定于文件类型的东西来污染您的vimrc
。
如果它不存在,请创建$HOME/.vim/after/ftplugin/html.vim
(在类 Unix 系统上)或$HOME/_vimfiles/after/ftplugin/html.vim
(在 Windows 上)并输入以下内容内容:
setlocal matchpairs+=<:>
abbreviate <buffer> <div> <div><CR><\div><up><CR><TAB>
abbreviate <buffer> <span> ...etc.
注意…
:help :setlocal
优于:help :set
,<buffer>
被添加到您的映射和缩写中,以防止它们泄漏到其他文件类型,请参阅:help :map-<buffer>
。 请参阅:help filetype
。
使用\\
进行换行,并使用|
来分隔命令。
autocmd! FileType html
\ set matchpairs+=<:>|
\ abb <div> <div><CR><\div><up><CR><TAB>|
\ abb <span> ...etc.
请参阅:help :bar
和:help line-continuation
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.