2

For easy typesetting of song sheets using the leadsheets LaTeX package I want to make a shortcut for vim.

Using the leadsheets package, chords are inserted into the lyrics like this:

^{Am7}Sunny

So to input this into vim, I have to press i^{Am7}[ESC] and move to the next word and do the same. However I'd like to be able to just hit some other key which puts me directly in insert mode, just enter the chord name and after exiting with [ESC] have the ^{ and } put around the inserted text automatically.

Is this possible?

1 Answer 1

1

You can do this fairly simply with a macro- type the following;

  • qa start recording macro to register a
  • W go to start of next WORD
  • q stop recording macro

Now, you need to navigate to the first insertion point (e.g., ^ go to start of line). Next,

  • qA continue recording macro to register a
  • i^{}escapei insert the text, move back one, and re-enter insert mode.
  • ctrl+oq stop recording macro, while in insert mode.

At this point you can type whatever you need between the {}, then press escape. This handles only the first entry. Pressing @a will allow you to continue inserting repeatedly.

This macro is equivalent to typing :let @a = "Wi^{}\<esc>i"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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