Vim - delete up to searched string

16,306

Solution 1

Try this

d/mystring

It won't delete the string itself.

Solution 2

d/mystring deletes everything up to mystring

Edit: aww, too slow :/

Solution 3

Greg Reynolds provided a working solution.
Alternatively if the search pattern is already defined, use:

dn

the n motion is exclusive, so the first character of your pattern won't be eaten.

Another alternative with the Easymotion plugin you can use <leader><leader>t<first letter of pattern (typically leader is backslash) ; then the character just before the pattern will turn into a letter; type this letter and you're done.

Share:
16,306

Related videos on Youtube

Martin Janiczek
Author by

Martin Janiczek

Updated on June 13, 2022

Comments

  • Martin Janiczek
    Martin Janiczek almost 2 years

    Is there a VIM command / key combination that would do something like dt/mystring (which doesn't work)?

    dta tries to find letter a on current line, but I'd like to delete everything up to searched string (possibly on some other line).

  • Sudheer
    Sudheer about 7 years
    This does the job. After the deletion, I have to press :noh to remove the highlighting of search term. Is there a way to delete till search string and not highlight further searches?