syntagma
syntagma

Reputation: 24334

"dt" motion in Vim working with mutiple lines

I very often use dt-some_character motion in Vim, to delete every character upto some_character. However, it works only for a single line.

Is there any analogue that would work for multiple lines?

Upvotes: 5

Views: 3840

Answers (4)

LikosX
LikosX

Reputation: 71

As said by Marth you could use the d/a_pattern_to_be_searched command. Since you have made a search, then you could use the n (next search result) [or the N (previous search result)] command in combination with delete.

Let's see an example, suppose you have this lines:

This is a first line - 01
This is a new line - 02
And this is the last line - 03

With the cursor on the i of is on the first line, giving d/line you'll get:

This line - 01
This is a new line - 02
And this is the last line - 03

Now if you give to vim the dn command, you'll get:

This line - 02
And this is the last line - 03

Also remember that you could use a count argument with the motion, so if you give the d3/line command instead of d/line in the above example, you'll get:

This line - 03

(we have said to vim: delete up to the third occurrence of "line")

Upvotes: 2

maggick
maggick

Reputation: 1422

If you want to make the same operation on sevral line:

You may use j. and/or a macro

for instance to delete until the character '7' on 2 lines (without macro):

df7j.

to delete until the character '7' on <n> lines, you need to record a macro:

qqdf7j<Esc><n>@q

If you want to delete from the current position until the character 7 on multiple lines (it will also delete the 7 character):

v/7<Esc>x

Upvotes: -1

Marth
Marth

Reputation: 24812

You could use d/some-character<CR> (e.g d/e then Enter to delete up to the next 'e').

Note however that this will modify the last-search register ("/).

Edit :

The counterpart to F is ? (search backwards) (d?X is inclusive, so no dT).

Upvotes: 11

Ingo Karkat
Ingo Karkat

Reputation: 172608

There are several plugins that extend the built-in f / t motions to cover multiple lines:

Another one that goes into the same direction, but via a different approach:

Upvotes: 5

Related Questions