VIM: insert empty ERB tags

廉价感情. 提交于 2019-12-29 09:04:05

问题


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

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5117991/vim-insert-empty-erb-tags

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!