本文介绍了VIM:插入空的ERB标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何插入空的ERB标签并将光标放在其中?它类似于使用Surround插件进行环绕,但是周围没有东西.

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.

例如,从此:

bla|bla

我想要这个:

bla<%= | %>bla

推荐答案

我将使用蒂姆·波普(Tim Pope)的Surround插件来完成此任务.

I would use Tim Pope's surround plugin to accomplish this.

在您的〜/.vim/after/ftplugin/erb.vim中添加以下内容

Add the following to you ~/.vim/after/ftplugin/erb.vim

let b:surround_{char2nr('=')} = "<%= \r %>"
let b:surround_{char2nr('-')} = "<% \r %>"

现在,当您按下<c-s>=时,它将按您的意愿插入<%= | %>.

Now when you press <c-s>= it will insert <%= | %> just as you wanted.

您可能还想看看蒂姆·波普(Tim Pope)的 ragtag插件,该插件已包含此类映射

You may also want to look at Tim Pope's ragtag plugin which has such mappings already included.

这篇关于VIM:插入空的ERB标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 04:37