Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vi/vim - delete from end line including final character

Tags:

vim

vi

I want to do something similar to this question VI (VIM): delete/change right to left? i.e. delete from the end of a line to the last instance of = in that line, which can be done using dT= with the cursor placed at the end of the line.

However this and other such commands do not delete the final character of the line, so I have to add an x to that command. I don't mind doing this, yet it seems surprising that vim wouldn't have a command to delete from the current character. Is there one that I just haven't been able to find?

like image 616
Leo Allen Avatar asked Mar 01 '12 14:03

Leo Allen


People also ask

How do we delete a line word and a character in vi editor?

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. You can also delete blank spaces in a line with the x command.

How do I delete a whole text in Vim?

Press the Esc key to go to normal mode. Type %d and hit Enter to delete all the lines.

How do I move the last word of a line in Vim?

In short press the Esc key and then press Shift + G to move cursor to end of file in vi or vim text editor under Linux and Unix-like systems. However, you can use the following keyboard shortcuts too.


2 Answers

if your cursor is at the end of the line, you could try

F=D

oh, didn't notice that OP wants to keep the '='. then:

T=D
like image 108
Kent Avatar answered Oct 02 '22 07:10

Kent


Alternatively, you can:

set virtualedit=onemore

This will let you move the cursor one characer beyond the end of the line. From that position, dT= will work as you expect.

like image 44
jcollado Avatar answered Oct 02 '22 08:10

jcollado