Delete/replace text without clobbering default register

2 Points

By default, if you delete some text in some way, vim puts it in the default " register. Sometimes you want to remove some text before you paste it back in. That will clobber the " register. These bindings let you remove text into the void register easily.

By default, Leader is \, so \d will delete text without overwriting "", meaning you can spam p without messing with "0 first. Works with a movement or in visual select mode.

nmap <Leader>d "_d
nmap <Leader>x "_x
nmap <Leader>c "_c
nmap <Leader>s "_s
nmap <Leader>r "_r
nmap <Leader>D "_D
nmap <Leader>X "_X
nmap <Leader>C "_C
nmap <Leader>S "_S
vmap <Leader>d "_d
vmap <Leader>c "_c
vmap <Leader>x "_x
vmap <Leader>s "_s
vmap <Leader>r "_r

Romain Lafourcade

Romain Lafourcade 9 years ago

Please consider using xmap instead of vmap to actually resctrict your visual mode mappings to visual mode and noremap instead of map to avoid remapping issues.