0

I am doing the exercise of learn vim the hard way

I have trouble mapping "the - key to "delete the current line, then paste it below the one we're on now".

I tried:

  • :map - dd p
  • :map - :dd p
  • :map - :dd <enter> p <enter>

Any help?

1 Answer 1

2

Before creating a mapping you should try the actual command by yourself: Here you want to delete a line with dd and then paste it with p. When you do that in normal mode you simply press the keys ddp without anything else in between, so that is what you need to do too in your mapping.

This means that you mapping should be map - ddp. You don't need to use the command mode (with : and <enter>) since dd and p are normal mode commands, i.e. the key you press directly in normal mode.

Also two other things:

  • If you continue reading learn vimscript the hard way (or maybe you miss this part) you'll see that it's important to use non recursive version of the map command so your actual mapping should be nnoremap - ddp
  • And <enter> is not a valid key representation in vimscript, you want to use <CR> instead.
1
  • 1
    Oh, I see, that makes sence. Thank you Commented Feb 12, 2021 at 10:31

Your Answer

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

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