vimtricks.wiki Concise Vim tricks, one at a time.

How do I delete through the end of the next search match from the cursor?

Answer

d/END/e<CR>

Explanation

When you need to remove text up to a known marker, a plain search motion is often almost right but stops at the start of the match. Adding a search offset solves that. d/END/e<CR> deletes from the cursor through the end of the next END match in one step.

This is especially useful in logs, generated files, or config blocks where delimiters repeat and you want precise cut ranges without entering Visual mode.

How it works

  • d starts the delete operator
  • /END<CR> supplies a search motion to the next END
  • /e applies an end-of-match offset, so the motion lands on the last character of END instead of the first

Without /e, d/END<CR> would usually leave END in place. With /e, the marker is included in the deletion.

Example

Given:

alpha END omega

With the cursor on a, press:

d/END/e<CR>

Result:

 omega

Tips

  • Use c/END/e<CR> to change (delete + insert) through the end of the match
  • Use y/END/e<CR> to yank the same range instead of deleting
  • Backward version: d?END?e<CR> for the previous match

Next

How do I run one substitution in nomagic mode so most regex characters are literal?