0

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

<%= @something %>

Whether in insert mode or not?

KendallB
  • 4,799
  • 4
  • 19
  • 21

2 Answers2

2

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.

romainl
  • 186,200
  • 21
  • 280
  • 313
David Brown
  • 13,336
  • 4
  • 38
  • 55
  • 2
    For readability sake, I tend to write my surround variables like so: `let g:surround_{char2nr('=')} = "<%= echo \r %>"`. You may also want to do this for only buffers with eco filetypes. I would suggest you create a file called `~/.vim/after/ftplugin/eco.vim` and use: `let b:surround_{char2nr('=')} = "<%= echo \r %>"`. The `b:var` will make the variable local to the buffer not global. – Peter Rincker Feb 28 '12 at 21:45
0

I wanted to add an additional alternative that I discovered later using snipMate. I could add a eco.snippets file to the snippets directory containing:

snippet =
    <%= ${1} %>

Took care of it to where I could just type = and then tab it into existence.

KendallB
  • 4,799
  • 4
  • 19
  • 21