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
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 <cs>=
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.