1

I currently have something like this in my vimrc. The reason i have this is because I do not want items to be copied to the default register when I delete or change.

"Copy the contents of delete to the black hole register
nnoremap dd "_dd
nnoremap d "_d
vnoremap d "_d
"Copy the contents of yank to the black hole register
nnoremap c "_c
nnoremap C "_C

Now lately i felt the need of adding a cut command as well which deletes and yank. I understand by default Vim does not have a delete but it has a cut command. However i have customised it to my liking. I wanted to know if there was a way for me to cut text that would work with the above keybinding. I tried doing this

"*dd

but that does not work and I guess that's because dd above gets mapped to "_dd Any suggestions on how I can accomplish a cut while maintaining my current shortcuts ?

  • 1
    wouldn't mapping your shortcut to dd work? like nnoremap #2 dd to map <F2> key to delete current line as well as yank – Sundeep Jul 18 '16 at 11:05
3

First off, I think your first mapping is unnecessary. Since the second d is in operator mode, it does not get remapped to "_d, so it maps out to "_dd. Secondly, you could do this:

nnoremap d "_d
nnoremap D "_D

nnoremap "*d "*d
nnoremap "*D "*D

This works since it uses noremap. Of course, you can change the register this yanks to, or the keystrokes you use to call it. For example, you could do

nnoremap "*d d
nnoremap "*D D

To make it yank to the unnamed register.

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.