如何在 Vim 中插入 ERB 标签? [英] How do I insert ERB-tags with Vim?
问题描述
如何在 Vim 中插入 <% %>
?我有 rails.vim.
How do I insert <% %>
in Vim? I have rails.vim.
推荐答案
我一直在使用 surround.vim 插件很久了,但不是 rails.vim 插件.事实证明,rails.vim 插件正在为围绕.vim 添加功能,或者搭载它.无论哪种方式,我都以这种方式工作:
I've been using the surround.vim plugin for a long time, but not the rails.vim plugin. Turns out that the rails.vim plugin is adding functionality to surround.vim, or is piggy-backing on it. Either way, I got it working this-a way:
- 安装 rails.vim 插件(如果尚未安装),然后打开 ERB 文档.Vim 应该将其识别为
eruby
文件类型. - 如果它不使用
:set filetype=eruby
Return 让 Vim 以你的方式看待事物. - 使用 v 或 V 直观地选择一些您想用 ERB 标签换行的文本.
- 按 S= 或 S-.(这是大写的 S)
- 所选文本应包含在
<%= %>
或<%- %>
块中.
- Install the rails.vim plugin if it isn't already, and open an ERB document. Vim should recognize it as a
eruby
filetype. - If it doesn't use
:set filetype=eruby
Return to make Vim see things your way. - Visually select some text you want to wrap with the ERB tags using v or V.
- Press S= or S-. (That's capital S)
- The selected text should be wrapped in a
<%= %>
or<%- %>
block.
我刚刚确认这也适用于列选择模式.
I just confirmed this works in column-selection mode too.
这在 rails.vim 帮助中有记录:从命令模式搜索 :h rails-surround
.如果你没有 rails.vim 的帮助,那是因为没有按照说明安装它:
This is documented in the rails.vim help: from the command-mode search for :h rails-surround
. And if you don't have the help available for rails.vim, it's because the instructions weren't followed for installing it:
:helptags ~/.vim/doc
rails.vim 插件也需要surround.vim 插件,因此必须事先安装.我在编辑时至少每分钟使用一次该插件的功能.它摇滚.
The rails.vim plugin requires the surround.vim plugin also, so that has to be previously installed. I use that plugin's functionality at least once a minute when I'm editing. It rocks.
这篇关于如何在 Vim 中插入 ERB 标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!