Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim - delete up to searched string

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

like image 262
Martin Janiczek Avatar asked Dec 22 '11 10:12

Martin Janiczek


People also ask

How do I delete a specific string in Vim?

In order to delete lines matching a pattern in a file using vim editor, you can use ex command, g in combination with d command. To remove lines that contains the string amos , in vim command mode, type the command below and press Enter. This will delete all lines containing the specified keywords.

How do I search and delete in Vim?

Basic Find and Replace In Vim, you can find and replace text using the :substitute ( :s ) command. To run commands in Vim, you must be in normal mode, the default mode when starting the editor. To go back to normal mode from any other mode, just press the 'Esc' key.

How do I delete a specific character in Vim?

To delete one character, position the cursor over the character to be deleted and type x . The x command also deletes the space the character occupied—when a letter is removed from the middle of a word, the remaining letters will close up, leaving no gap. You can also delete blank spaces in a line with the x command.


1 Answers

Try this

d/mystring 

It won't delete the string itself.

like image 184
Greg Reynolds Avatar answered Oct 23 '22 15:10

Greg Reynolds