Vim: delete without copy

Fang Jin
2 min readJan 13, 2024
Photo by Thomas Park on Unsplash

I’m a fan of vim, always providing me a boost of efficiency when I need it. But I have to admit, sometime it gets me pretty frustrated on things that is quite obvious to do in other basic editors, such as delete.

If you hit x , you’d expect to remove a character under your cursor.

abcdefghijklmn
-
x

Pretty straight forward. But behind the scene, it also does something extra, by putting the removed character into the buffer. So next time when you paste with p, it behaves as if you have pressed Ctrl-C on your keyboard. Some might find this useful, but some can find this extremely annoying.

Lately I have been doing a lot of editing such as the following.

···Q····
······Q·
··Q·····
·······Q
·Q······
····Q···
Q·······
·····Q··

I need to copy and paste while deleting. But I really don’t want to paste the deleted character, instead I want to keep pasting the same character, such as . in my case. The delete bothered me before, but this really drove me nuts.

Luckily it also bothered other people. So I searched around and the solution actually isn’t complicated at all.

Just put a line in .vimrc .

nnoremap x "_x

--

--

Fang Jin

#OpenToWork Front-end Engineer, book author of “Designing React Hooks the Right Way” sold at Amazon.