开发者

VIM: insert empty ERB tags

开发者 https://www.devze.com 2023-02-13 05:13 出处:网络
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.

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, fr开发者_C百科om this:

bla|bla

I want get this:

bla<%= | %>bla


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

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

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

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.


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 :

snippet ta
     <%= ${1} %> 

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号