daniel451
daniel451

Reputation: 10992

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

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).

Upvotes: 1

Views: 373

Answers (1)

Amadan
Amadan

Reputation: 198294

T=D (Jump to after =, delete to end of line) is the shortest way, I believe.

You can do it without the movement first, but it is considerably more complex: :s/=\@<=.*// CR

Upvotes: 2

Related Questions