Search code examples
vimkey-bindings

How can I map _ (underscore) in vim?


I want my vim command x to delete a character but not copy it to a register.

Through googling, I found that "_x does the trick, but if I try to remap to x, whenever I press x my vim freezes. I'm using:

nmap x "_x

I tried various other things as well, but none seemed to work and I cannot find any information on why this wouldn't work with underscore


Solution

  • :nnoremap x "_x

    When you make that mapping, it contains the character you're remapping, which makes it what is called a "recursive" mapping. All that means is that it tries to run itself over and over and over, and never quits (because it never actually encounters an error condition). To make a mapping and tell it "don't be recursive - any characters in the value of this mapping should have their native, base meanings in vim -- not whatever I might have mapped them to", you just prepend 'nore' to the map command (but after the mode specifier), as shown above.