0

I've tried the following, but it doesn't work.

inoremap <C-\> <Esc>$a<Space>do<Space><Bar><Bar><CR>end<Esc>k$i

I'm trying to map a shortcut for ruby do || .. end blocks.

2
  • 1
    I'm not exactly sure your mapping does what you want it to do but, at least, the || insertion works, here.
    – romainl
    Aug 22, 2013 at 20:38
  • It works for me. I get " do || end" (with a newline before "end") when I run the mapping, with the cursor between the pipe/bar characters in insert mode.
    – Heptite
    Aug 22, 2013 at 22:11

1 Answer 1

0

If I understood your question correctly, you want to insert some boilerplate code. There are several ways to approach this:

  • Take a look at the vim-snipmate ViM plugin. Does what you want and then some. Highly recommended.
  • Record a sequence of keypresses (:help q), which you can later replay (:help @). This sequence is recorded in the register, which is not the same as mapping/macro, but achieves your goal still, plus it can be made persistent (i.e. survive ViM restarts).
  • Do an actual mapping: :inoremap <C-\> <Esc>A<Space>do<Space><Bar><Bar><CR>end<Esc>ko

Hope this helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .