我们可以在 vim 中为给定文件类型使用多个片段文件吗?
使用snipmate + vim时,是否可以有很多片段文件 加载给定的语言/文件类型?
前任: snipmate 附带 javascript.snippets
我还加载了 mootools 片段并将其添加到我的 vimrc 中: autocmd FileType javascript set ft=javascript.mootools
现在我可以使用
- 库存 js 片段和
- mootools 片段,
我想添加第三组片段 javascript.myCustomSnippets
,这将还加载文件类型javascript
。
当我尝试使用类似的东西添加自定义片段时 autocmd FileType javascript set ft=javascript.myCustomSnippets
它会覆盖/禁用 mootools 片段,但默认的 javascript 片段继续工作。
我该如何实现这一点,或者是否可能?
ps:我知道我可以将我的代码片段添加到默认的 javascript 代码片段文件中,但由于我已在 .vim/bundle/
文件夹中同步了 snipmate github 存储库,因此我想保留个人的东西与实时存储库分开。
我的解决方案
最终让我的文件并行工作的具体解决方案是像这样构建我的文件(顺便说一句,我使用 pathogen 自动加载 bundle
目录)
~/.vim/bundles/
snipmate.vim/snippets/javascript.snippet
vim-snippets.mootools/snippets/mootools.snippet
vim-snippets.myCustomSnippets/snippets/javascript.snippets
通过将我的文件命名为“javascript.href” snippets”它会与默认值一起自动加载。
When using snipmate + vim, is it possible to have many snippet files
load for a given language/filetype?
Ex:
snipmate comes with javascript.snippets
I've also loaded the mootools snippets and added this to my vimrc:autocmd FileType javascript set ft=javascript.mootools
Now I can use
- the stock js snippets
- the mootools snippets
I want to add a 3rd set of snippets, javascript.myCustomSnippets
, that will also load for the filetype javascript
.
When I try to add my custom snippets using something like thisautocmd FileType javascript set ft=javascript.myCustomSnippets
it overwrites/disables the mootools snippets, however the default javascript snippets continue to work.
How do I accomplish this, or is it possible?
ps: I know I could just add my snippets to the default javascript snippets file, but since I have the snipmate github repo synced inside my .vim/bundle/
folder, I want to keep the personal stuff separate from the live repo.
My Solution
The specific solution that finally got my files working side-by-side was to structure my files like this (by the way, I'm using pathogen to auto-load the bundle
dir)
~/.vim/bundles/
snipmate.vim/snippets/javascript.snippet
vim-snippets.mootools/snippets/mootools.snippet
vim-snippets.myCustomSnippets/snippets/javascript.snippets
By naming my file "javascript.snippets" it's auto-loaded along with the defaults.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Ruy Diaz 关于个人的东西是正确的,你可以将你自己的所有片段保存在“~/.vim/snippets”中,并且 github 存储库不会有任何问题。如果这对您不起作用,则
g:snippets_dir
变量可能具有错误的值 - 只需在您的 vim 文件中显式设置即可。至于组合多个片段,您可以使用ExtractSnipsFile函数。这应该可以完成您想要的操作,而不会弄乱点文件类型语法。
假设您有以下三个片段文件,全部位于片段目录中:
创建一个文件“after/plugin/snippets.vim”并将以下内容放入其中:
这将关联所有这些具有
javascript
文件类型的片段,无需显式自动命令。有关更多信息,您可以尝试:help ExtractSnipsFile
。Ruy Diaz is right about the personal stuff, you can keep all of your own snippets in "~/.vim/snippets" and you won't have any problems with the github repo. If this is not working for you, the
g:snippets_dir
variable might have the wrong value -- just set it explicitly in your vimfiles.As for combining several snippets, you can use the
ExtractSnipsFile
function. That should do what you want without messing around with dotted filetype syntax.Let's say you have the following three snippet files, all in your snippet directory:
Create a file "after/plugin/snippets.vim" and place the following in it:
This will associate all of these snippets with the
javascript
filetype, no explicit autocommands needed. For more information, you can try:help ExtractSnipsFile
.在 .vim 目录中创建一个 snippets 文件夹并将代码片段放置在其中。在其中创建一个名为 javascript.snippets 的文件,您应该同时拥有 snipmate 片段和自定义片段。
Create a snippets folder inside your .vim directory and place your snippets there. Create a file called javascript.snippets in there and you should have both the snipmate snippets and your custom ones available.
仅供进一步参考, :h snipMate 指出: 扩展:
扩展给定文件类型的片段。
这将包括给定文件类型的所有片段。
只需将您自己的代码片段文件放入 ~/.vim/snippets/objc.snippet
Just for further reference, the :h snipMate states: extends:
extends the snippets of the given filetypes.
this would include all snippets for the given filetypes.
And just put your own snippet file in ~/.vim/snippets/objc.snippet
是的当然。首先使用 github.com/MarcWeber/vim-addon-manager 这样你就不会错过上游的更改。 M. Sander 的 Snipmate 已被分叉,因为他从未回复有关合并请求的电子邮件。这就是我和加尔巴斯改进它的原因。新版本可以在 github.com/garbas/vim-snipmate 找到。
您有一个全局scope_aliases 字典,可用于将文件类型与片段文件关联起来。这样您就可以根据个人喜好轻松地向 html 文件添加 js 片段支持。还有一些更改,但我厌倦了重复它们。
Yes of course. First use github.com/MarcWeber/vim-addon-manager so that you don't miss upstreams changes . M. Sander's snipmate has been forked because he never replied to emails about merge requests. That's why I and garbas improved it. The new version can be found at github.com/garbas/vim-snipmate.
You have a global scope_aliases dictionary you can use to associate filetypes with snippet files. This way you can add js snippet support to html files easily based on personal preferences. There are some more changes but I'm tired of repeating them.
由于您使用的是 Pathogen,因此您需要做的就是将自定义 Snippets 文件夹添加到包目录中。例如:
~/.vim/bundles/mySnippets/snippets/php.snippets
Since you are using pathogen than all you need do is add a custom Snippets folder to the bundles directory. For example:
~/.vim/bundles/mySnippets/snippets/php.snippets