Often I want to delete something in Vim without moving it to a register. Is there a method of doing this? I find that having to explicitly specify the register "a
to be a little much sometimes.
2 Answers
It sounds like you're actually asking two related questions here:
- You want to delete text without it appearing in any registers
- You want to be able to specify a default register other than
"
The first one can be done, just use the _
register, which is called the "black hole" register, instead of something like the a
register. For example: "_dd
The second one can't be done, as far as I know.
See :help registers
.
-
That still adds two more characters to the repeated task, I wanted to change the default register to _ so I shave two keystrokes off of a delete-paste cycle. Jul 30, 2012 at 17:38
-
@EvanCarroll: You don't need to specify a register for a delete-paste cycle. Both operations use the default register (") by default.– garyjohnJul 30, 2012 at 18:09
-
Right, but I don't want the delete to clobber what is in the default register because I want to paste it without specifying a non-default register for the paste, or the delete. Jul 30, 2012 at 18:12
-
Got it. In that case, and as Heptite wrote, I don't see a way to do that.– garyjohnJul 30, 2012 at 18:34
You can always do something like this:
nnoremap d "_d
vnoremap d "_d
But I wouldn't recommend it: Vim's default should stay the way they are.
Instead of "_d
, I use these mappings to delete into the black hole register:
nnoremap <leader>d "_d
vnoremap <leader>d "_d
That's only shorter by one key but it's better than overwriting a Vim default.
I use this mapping when I need to paste something several times:
vnoremap <leader>p "_dP
Which goes like this:
10 yank something
20 select something else
30 paste over it
40 GOTO 20