如何在模式行上加载 .vim 文件
对于一些特定文件,我需要一组映射,但我不想在我的 ~/.vimrc
文件中激活它们。所以我在文件 XXX.vim
中定义了它们。 如何在模式行上加载 XXX.vim
以及它应该放在我的 .vim
目录中的什么位置?
For a few specific files I need a set of mappings, which I don't want to be active in my ~/.vimrc
file. So I defined them in a file XXX.vim
.
How can I load XXX.vim
on a mode line and where should it be placed in my .vim
directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于显而易见的原因,您无法在模型行中获取脚本。您所能做的就是设置一些选项。
让某些选项/映射/命令可用于某些文件而不是其他文件的规范方法是使用
:help autocommand
,如下所示:您可以将上面的模式用于带有
的所有文件foo
扩展名或类似foo/bar/*
的内容,用于foo/bar/
下的所有文件等。如果您只想为特定的 文件类型,说
ruby
,那么最好使用内置的 ftplugin 机制:确保您的
vimrc
中有以下任一行>:如果该文件不存在,则创建该文件(以及必要的目录):
将缓冲区本地映射添加到该文件:
You can't source a script in a modeline for obvious reason. All you can do is set some options.
The canonical way to have some options/mappings/commands available for some files and not others is to use an
:help autocommand
like this one:You can use the pattern above for all files with the
foo
extension or something likefoo/bar/*
for all file underfoo/bar/
, etc.If you want those mappings only for a specific filetype, say
ruby
, then it is best to use the built-in ftplugin mechanism:Make sure you have either of the following lines in your
vimrc
:Create this file (and the necessary directories) if it doesn't exist:
Add your buffer-local mappings to that file: