Let's say I have this text with | as my cursor:

<<<<<<< HEAD
>>>>>> XXXX GGg| 

Now, I'd like to select from >>>> to say second=== or line containing <<<< word. How do I do that?

4 Answers 4


To answer your question in a more general way, you can combine the visual mode with any motion you use in normal mode. That means that you can use f, t, w, etc but you can also use the search:

In your case with your cursor after GGg you can start reverse search mode with ? and type < in your search prompt. When you type Enter the end of your selection will end up on the last < of the first line. (Maybe linewise visual selection can be useful for you here, it is triggered with Shift+v.

Note that if you already did the search you can use the motions n and N to move your visual selection too.


You better be more clear|specific...

Now, I'd like to select from >>>> to say second===


or line containing <<<< word. How do I do that?


And if you want the answer to "How to end selection at an occurrence of a word?"

With the text

he|llo beautiful world

Where | is your cursor and you want to select till the end of the "beautiful"

v/ful/e which is

  • v visual mode
  • /ful search for "ful"
  • /e move cursor to the end of word found

After you enter visual mode (linewise with V is probably what you want), you can use the ? to search backwards for the specific string you're looking for.

I'd like to select from >>>> to say second ===

Use V, then ?^====== and press enter.

Use n if you want to continue the selection to the first ====== line.

or line containing <<<< word.

Use V, then ?^<<<<<< and press enter.

  • ^ go 1st >
  • va> select :h a> block
  • V a> is characterwise, need to convert to linewise.

Another way is to add <> to :h 'matchpairs' :

set mps+=<:>

and do:

  • V start visual linewise
  • ^ go to 1st >
  • % goto matching < for current >.

If there are < or > in the body, add an e after ^ to search match for the most outside >.

For the === part, use ?^=== to search backward, use n to repeat last search.

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.