If I start with this file:


and press ddp, I expect to get this:


but instead I get this:


What am I doing wrong?

  • 1
    dd performs a linewise operation. To paste within the current line, the delete operator needs to be a given a characterwise motion. More details here
    – husB
    Mar 3 '20 at 5:28
  • 1
    To accomplish that in three keystrokes: DJp
    – filbranden
    Mar 3 '20 at 6:11

Like husB commented you have to use a characterwise motion. Note that D deletes from the current cursor position to the end of the line and doesn't delete the line itself.

You could overwrite what dd does but I would recommend you map your expected behaviour to a new command, <leader>d in the following mapping:

:nmap <leader>d 0D"_dd

The command does the following:

  • 0: go to the beginning of the line
    • 0 includes whitespace, use ^ or _ instead to go to the first non-blank character
  • D: cut characterwise to the end of the line
    • also includes whitespace, can be replaced by dg_ to cut to the last non-blank character instead, see this answer
  • "_ is the "black hole register" to keep your default register (used by p) clean
  • dd: cuts the now empty line into "_

Instead of dd, can use:





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.