VIM:插入空ERB标签
如何插入空 ERB 标签并将光标放入其中?它与使用环绕插件进行环绕类似,但没有任何可环绕的内容。
例如,从此:
bla|bla
我想得到这个:
bla<%= | %>bla
How can I insert empty ERB tags and put cursor inside it? It is similar to surrounding with surround plugin, but there is nothing to surround.
For example, from this:
bla|bla
I want get this:
bla<%= | %>bla
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会使用 Tim Pope 的环绕插件来完成此任务。
将以下内容添加到 ~/.vim/after/ftplugin/erb.vim
现在,当您按
=
时,它将插入<%= | %>
就像你想要的那样。您可能还想看看 Tim Pope 的 ragtag 插件,它已经包含了此类映射。
I would use Tim Pope's surround plugin to accomplish this.
Add the following to you ~/.vim/after/ftplugin/erb.vim
Now when you press
<c-s>=
it will insert<%= | %>
just as you wanted.You may also want to look at Tim Pope's ragtag plugin which has such mappings already included.
要插入预定义的文本块,您应该查看 Snipmate 。它将插入代码并将光标定位到预定义的位置。
我不确定是否支持 ERB,但添加您自己的代码片段非常容易。
例如,
在 erb.snippets 中,类似 : 的内容应在键入
ta
时插入文本。但是,您可以在线找到大量 Snipmate 片段。
例如, https://github.com/scrooloose/snipmate-snippets 包含许多预定义的片段。
请参阅之前的答案了解如何安装它们。
To insert predefined block of text, you should have a look at Snipmate. It will insert code and position the cursor to a predefined position.
I am not sure ERB is supported but it is very easy to add your own snippets.
For example, something like :
in erb.snippets should insert the text when typing
ta
However, you can find plenty of snippets for Snipmate online.
For example, https://github.com/scrooloose/snipmate-snippets contains lots of predefined snippets.
See previous answer on how to install them.