In my vimrc I have

nnoremap d "_d
nnoremap yd dd

to not save lines when I delete.
Is it possible to create a mapping that when I press e.g. d4y it will cut 4 lines and save them into buffers?
I understand this is the functionality of e.g. d4d, but I would like to keep dd as removal, not saving lines into the copy buffer.

1 Answer 1


I think you are confusing buffers which are in memory representation of a file (:h buffers) and registers which are in memory places to store yanked and deleted text (:h registers). I think you would benefit from reading the doc on these topics and get a better understanding, you'll get less confusion in the long run.

First a reminder on commands and motions:

  • dd is a normal mode command on its own, it doesn't take a motion but it does take a count. It is a standalone command which deletes [count] lines (when used with [count]dd, otherwise [count] is 1 by default).
  • d is a command which takes a motion. It deletes the text that {motion} moves over. E.g. dw delete text until the next word.
  • A motion (:h {motion}) is a way to move over text (like w, j, }, etc)

I think in your question you are confusing motions and commands: d4y doesn't really have any sense because y is a command like d so giving the motion 4y to the command d is not possible.

What you could do is the following:

nnoremap d "_d
nnoremap yd d

This would remap the command d to always use the black hole register "_ and this would create a new command yd which would behave like the original d command.

This way you can use d4w or d4j to delete words or lines without keeping them in the unnamed register, and yd4w and yd4j would do the same while keeping the deleted text.

However that would also mean having the following to keep the dd command consitent:

nnoremap dd "_dd
nnoremap ydd dd

Which might introduce some issues depending on your :h 'ttimeout' and :h 'ttimeoutlen' settings.

So all in all my advise would be to not try to do what you are doing:

A good rule of thumb when creating mappings is to always extend Vim's built-in feature and not override them because overriding vim commands is the best way to create inconsistencies and the longer you will use that the more you will realize that your configuration is breaking a lot of other stuff and you will keep creating fixes to your config which will be really painful.

So as someone who's been using vim for many years and have done the same kind of mistakes, I would strongly recommend you to get used to use d and "_d when you need to, because that will also apply to other commands x or S or c, etc... and overriding one will throw you into a considerable loss of time.

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.