4

How to map keystrokes to a command in vim?

For example, I would like to create a custom command Cmt, and I could use it to comment out lines 10-20 like this: :10,20Cmt

I have tried something like :command -range Cmt <line1>gg O ... but it didn't work.

4

You want to use the :normal! command:

command -range Cmt normal! <line1>ggO

Commands take everything to the right of the name (Cmt) and runs it as an ex command:

command -nargs=1 LetX let g:x = '<args>'

Substitutions are made on the command before it's executed. So, running 10Cmt will execute :normal! 10ggO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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