Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
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 '13 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 '13 at 22:11

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.