定义仅适用于特定文件类型的插入模式映射
我应该知道这一点,但我现在脑子一片空白......长夜......
如何定义一个仅当某种文件类型处于活动状态时才处于活动状态的映射(例如,markdown,我希望定义一个映射/缩写来插入括号][,因为我的语言布局中的键盘上没有它们)?
I should know this, but my mind is blank right now ... long night ...
How to define a mapping that is active only when a certain filetype is active (say, markdown and I wish to define a mapping/abbrev for inserting brackets ][ since I don't have them on my keyboard in my language layout)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
定义仅在具有特定
文件类型
的缓冲区中有效的映射值,可以使用文件类型自动命令的组合(请参见
:help
、autocmd
:help FileType
)和本地映射(请参阅:help map-local
)。To define a mapping effective only in the buffers having certain
filetype
value, one can use the combination of a filetype autocommand (see
:help
,autocmd
:help FileType
) and a local mapping (see:help map-local
).第一个强制性步骤确实是使用
:h :map-
定义缓冲区本地映射,如 ib 所说。然后你就可以选择了。您可以:
当我们只将 vim 用于几种语言/文件类型并且我们只有很少的映射/命令/缩写/...时,第一种方法很好。在 Vim 的前几年很好。经过一定数量的特定于 ft 的设置后,第二种解决方案是首选。
(顺便说一句,这个主题是重复的,但我现在懒得搜索其他帖子)
The first, mandatory, step is indeed to define buffer local mappings with
:h :map-<buffer>
as ib said.Then you have the choice. You can :
The first approach is fine when we only use vim for a couple of languages/filetypes and when we have very few mappings/commands/abbreviations/... It's fine the first couple of years in Vim. Past a certain amount of ft-specific settings, the second solution is the one to be preferred.
(BTW, this subject is a duplicate, but I too lazy right now to search for the other posts)
在适当的地方添加(例如
~/.vimrc
):Add where appropriate (e.g.
~/.vimrc
):