有没有办法在vim中插入几行预先写好的东西?
我经常使用以下两个 HTML 片段:
<a href="" title=""></a><br />
<br />
和
<a href="" title=""</a><br />
<hr class="grp">
有没有一种方法可以快速将其中一个插入到我的文件中?
I use the following two snippets of HTML frequently:
<a href="" title=""></a><br />
<br />
and
<a href="" title=""</a><br />
<hr class="grp">
Is there a way where I can quickly insert one or the other into my file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以将它们存储在文件中,然后
将它们“读”到光标所在的当前文件中。
You can store them in files, then
to 'read' them into the current file, where the cursor is.
您可以使用许多插件/脚本来增强 Vim。谷歌的快速点击给我带来了 snipMate (还没有尝试过),这似乎符合你的要求。当然,您也可以通过读取文件来插入片段,但也许使用制表符补全更方便一些。
如果您发现自己输入了大量 html,我强烈推荐 zencoding 插件。 Zencoding 扩展了 html/xml 标签,并提供了更多编写 html 的方法(例如,将某些行转换为未排序的列表)。
You can enhance Vim with many plugins/scripts. A quick google hit brought me snipMate (haven't tried it), which seems to do what you ask for. Of course, you can also insert a snippet by reading a file, but maybe using tab-completion is a little bit more convenient.
If you find yourself typing a lot of html, I can strongly recommend the zencoding plugin. Zencoding expands html/xml tags and offers many more ways to write html (e.g. converting some lines into an unsorted list).
为什么不在你的 .vimrc 中添加缩写 我
的 .vimrc 中有以下内容用于 c++ 文件:
它让我只需键入“cout”,然后打印:
将光标放在引号内...
在 vim 中键入“:help iabbrev”有关其工作原理的合理教程...
Why not add an abbreviation to your .vimrc
I have the following in my .vimrc for c++ files:
It lets my just type "cout" and then prints:
Placing my cursor inside the quotes...
Type ":help iabbrev" in vim for a reasonable tutorial on how this works...
您可以映射一个按钮以将文本插入前一行:
有趣的位用 ^ 标记,并在下面进行解释
o
开始在光标下方的行插入,O
相反会在光标上方的行开始插入,
插入换行符,
退出插入模式。如果您愿意,可以使用
:imap
而不是:map
这将使其在插入模式下工作。在这种情况下,您可能希望在开始时退出插入模式,然后在结束时不退出You can map a button to insert the text into the preceding line:
The interesting bits are marked by ^'s and explained below
o
starts inserting on the line below the cursor,O
instead would start inserting on the line above the cursor,<ENTER>
inserts a newline character,<ESC>
exits insert mode.If you would prefer you can use
:imap
instead of:map
this will make it work in insert mode. In that case you would probably want to escape out of insert mode at the beginning and then not escape out at the end