如何在 VIM 中向 snipMate 添加新片段 [英] How to add new snippets to snipMate in VIM

查看:38
本文介绍了如何在 VIM 中向 snipMate 添加新片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 VIM 的 sniptMate 插件并喜欢它,但是,由于我的片段集合并不大,我希望能够动态添加新片段,而不是打开片段文件并创建一个新的片段片段,因为我正在开发中.

Ive just started using the sniptMate plugin for VIM and love it, however, since my collection of snippets isn't huge, I'd like to be able to add new snippets dynamically rather than opening the snippets file and creating a new snippet as I am in the middle of development.

在我编写代码时,我意识到可以将某些特定的代码段保存为代码段,以免我再次输入膨胀代码的麻烦,此时我希望能够在不打开代码段文件的情况下添加代码段对于我当时使用的语言.

As I am coding something I realize that some specific piece of code can be saved as a snippet to save me trouble of typing the bloat code again, at this time I want to be able to add a snippet without opening the snippet file for the language I am using at the time.

推荐答案

我不确定是否应该这样做,但您可以尝试从您所在的文件中调用 MakeSnip 函数目前正在工作.例如:

I'm not sure it's meant to be done like this but you can try calling the MakeSnip function from within file you're currently working on. For example:

:call MakeSnip(&ft, "foo", "<foo>${1}</foo>")

&ft 将传递您当前正在编辑的文件的文件类型,"foo" 是触发器,"<foo>${1}</foo>" 是替换文本.

&ft will pass the filetype of the file you're currently editing, "foo" is the trigger and "<foo>${1}</foo>" is the replacement text.

当然,像这样创建的片段不会持久存在.那么为什么不在另一个缓冲区中打开片段文件,根据需要在那里定义新片段,然后执行:

Of course, snippets created like this won't persist. So why not have the snippets file open in another buffer, define new snippets there as necessary, then do:

:call ReloadSnippets(&ft)

并且您的新代码段将可用.您甚至可以定义一个 autocmd 来在编写代码片段文件时调用 ReloadSnippets 函数.

and your new snippet will be available. You could even define an autocmd to call the ReloadSnippets function when you write the snippets file.

这篇关于如何在 VIM 中向 snipMate 添加新片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆