Vi/vim - delete from end line including final char

2019-03-26 15:24发布

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?

标签: vim vi
5条回答
Emotional °昔
2楼-- · 2019-03-26 15:28

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
查看更多
神经病院院长
3楼-- · 2019-03-26 15:34

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.

查看更多
地球回转人心会变
4楼-- · 2019-03-26 15:43

A bit more convoluted, but more powerful - I'm not sure if you intend to do one line at a time, or lots... use regular expression replace.

single line:
^               # go to beginning of line
:s/=[^=]*$/=/   # remove everything after =

whole file:
:%s/=[^=]*$/=/gc   # replace every instance in file, with prompts. remove c for no prompt.
查看更多
Anthone
5楼-- · 2019-03-26 15:52

An alternative is to :set virtualedit=onemore, such that you can do: $dT=.

Reference at :help 've'.

查看更多
▲ chillily
6楼-- · 2019-03-26 15:53

What about using T=d$? would that work?

查看更多
登录 后发表回答