Vim: delete everything in a line after character without moving cursor in the first place

时间:2019-01-28 05:54:54

标签: vim

Suppose the following line and cursor position:

foo = some_func(1 +[ ]2)
                   ^^^
              cursor position

Using di + ( I could easily get rid of everything inside the brackets or delete everything to line start or end using d^ and d$ respectively, but what would I do if I would like to delete everything that comes after =?

The resulting line should be:

foo =[ ]
     ^^^
cursor position

dT+= deletes everything until (backwards) the character =, but it still leaves 2) in the line, ending up in:

foo =[2])
     ^^^
cursor position

I could, of course, jump to = first and then use d$ to delete everything until line ending, but I would prefer a simple shortcut based on current cursor position without the need to move the cursor (if such a shortcut exists).

1 个答案:

答案 0 :(得分:2)

我相信

T = D (跳至=之后,删除到行尾)是最短的方法

可以先进行移动,但这要复杂得多::s/=\@<=.*// CR