Vi/vim - delete from end line including final character

我是研究僧i 提交于 2019-12-04 19:29:09

问题


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?


回答1:


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



回答2:


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.




回答3:


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




回答4:


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

Reference at :help 've'.




回答5:


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.


来源:https://stackoverflow.com/questions/9518324/vi-vim-delete-from-end-line-including-final-character

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!