如何在 Vim 中创建短片断? [英] How to create short snippets in Vim?
问题描述
我最近开始使用 Vim 作为我的文本编辑器,目前正在处理我自己的自定义.
I have recently started using Vim as my text editor and am currently working on my own customizations.
我认为键盘映射几乎可以做任何事情,但目前我几乎只将它们用作一种片段工具.
I suppose keyboard mappings can do pretty much anything, but for the time being I'm using them as a sort of snippets facility almost exclusively.
因此,例如,如果我输入 def{TAB}
(:imap def{TAB} def ():
),它会扩展为:
So, for example, if I type def{TAB}
(:imap def{TAB} def ():<ESC>3ha
), it expands to:
def |(): # '|' represents the caret
这按预期工作,但是当我输入包含def"的单词并且对扩展它不感兴趣时,当 Vim 等待完整命令时,我发现这很烦人.
This works as expected, but I find it annoying when Vim waits for a full command while I'm typing a word containing "def" and am not interested in expanding it.
- 有没有办法避免这种情况或为此更有效地使用此功能?
- 是否有其他 Vim 功能更适合于此?
快速浏览一下 SnippetsEmu 后,它看起来像最好的选择,而且比我最初想象的更容易定制.
After taking a quick look at SnippetsEmu, it looks like it's the best option and much easier to customize than I first thought.
继续前面的例子:
:Snippet def <{}>():
定义后,您可以通过键入 def{TAB}
来扩展您的代码段.
Once defined, you can expand your snippet by typing def{TAB}
.
推荐答案
SnippetsEmu 是一个有用的片段插件.
SnippetsEmu is a useful snippets plugin.
这篇关于如何在 Vim 中创建短片断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!