Search code examples
vimcoffeescripteco

Surround Embedded Coffeescript in ECO in VIM


Are there any shortcuts to surround embedded Coffeescript (in eco templates) in VIM?

<%= @something %>

Whether in insert mode or not?


Solution

  • The surround plugin can do this. You will have to set up a custom replacement to do this. One of the examples in the surround help file actually does exactly what you want. The example says to add the line

    let g:surround_61 = "<%= \r %>"
    

    to your .vimrc.

    In this the \r is the placeholder for whatever text you are surrounding and the 61 in the variable name means that ASCII character 61 will be the shortcut for this surround, which is =. To use this you then use one of surround's bindings and type = as the surround character. For example the command ysiW= would surround the current word with <%= ... %>. The ys part is the key binding to add surrounding text. iW is the motion that will be surrounded (it represents "inside word") and then = is the surround to use, which here is set up to be a custom surround.