When using evil mode search, is there a way to act on the currently highlighted search result by...

  • Converting it into a selection.
  • Treating it as a text object.
  • Having the ability to specify the end of the match when editing.

Example edits could be:

  • Delete the text.
  • Make the text upper case.
  • Change the text for something else.

This something I often want to do when the search is only part of a word, in this case operating on the word is editing past the part of the word I searched for.

2 Answers 2


After looking into VIM documentation, I found a way to do this which works in evil-mode too. See Visual select current search result.

gn selects the highlighted text, after pressing this you can operate on the selection.

Pressing n. repeats the operation on the next match.

Note that you may use gn in place of w in many operations.

  • cgn can be used to change the current search result.
  • gUgn makes the search result upper case.
  • dgn to delete the current highlight.

While this on it's own is useful, it would be nice to have a way to enable select-on-search (for example, if the search began in visual mode, or if gn was pressed on the previous search result), this is a bit out of the scope of this question though.


For the first point in your question I do not know a default way, but you could define a custom function (and bind it to some key) yourself to change the last match to a selection so that you can further edit it the evil way:

(defun my-evil-last-match-to-region ()
  (evil-visual-select evil-ex-search-match-beg evil-ex-search-match-end))

You could bind it to t (or f), which are keys with similar functionality that I guess most users do not use both:

(define-key evil-normal-state-map (kbd "t") 'my-evil-last-match-to-region)

Subsequently, you can edit it the evil way using e.g. d, U, c. Or you could "specify the end/beginning of the match" using l/oh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.