Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete next character (not current!) in vim?

Tags:

vim

I often find myself needing to delete the character after the cursor, but not the current character. What's the shortest way to do this in normal mode in vim?

like image 538
AatG Avatar asked Mar 28 '14 04:03

AatG


People also ask

How do I delete a character in Vim?

To delete one character, position the cursor over the character to be deleted and type x . The x command also deletes the space the character occupied—when a letter is removed from the middle of a word, the remaining letters will close up, leaving no gap.


3 Answers

lx will do the trick, or lxh if you want to return your cursor to the original position.

It simply moves the cursor forward and deletes the character under it.

If that's not short enough, you can map it to a single keypress:

:map <f5> lxh

Then just use the f5 function key.

like image 75
paxdiablo Avatar answered Oct 24 '22 18:10

paxdiablo


I believe there are many ways to do that, there is another 3-strokes way:

xpX

note that, either xpX or lxh would fail if your cursor on the EOL. :)

like image 21
Kent Avatar answered Oct 24 '22 17:10

Kent


The shortest sequence that I know is also the obvious one:

Type "l x h" in command mode.

like image 40
Ken Anderson Avatar answered Oct 24 '22 19:10

Ken Anderson