Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a command in Vim/Vi to move the cursor to the end of a search highlight?

Tags:

vim

vi

Are there any commands in Vim/Vi to move within a selected search segment?

For instance, if I search for a word, are there any commands to motion the cursor to the end of the highlighted segment? Say I have a word, "FishTaco" and I want to search for all instances of "Fish" and insert something after it. I know I could do a global replace, but what if I want to only make the change in a couple non-sequential instances?

I could see where it would be convenient to be able to motion the cursor to the end of the current highlighted segment to perform an action.

like image 201
Jordan Parmer Avatar asked May 22 '12 18:05

Jordan Parmer


People also ask

How do I move the cursor to the last line in vi editor?

Press ^ to move the cursor to the start of the current line. Press $ to move the cursor to the end of the current line.

What is the command to move your cursor to the end of the file vim?

Move cursor to end of file in vim In short press the Esc key and then press Shift + G to move cursor to end of file in vi or vim text editor under Linux and Unix-like systems.

How do I jump to the end of a line in Vim?

We may need to end the last line from anywhere in the file. Even the cursor has located the start of the file you can move the end of the last line with the following steps. Press the ESC key. Press G to move the last line and press $ to move the end of the line.


2 Answers

You can do it with this:

/Fish/e

The /e at the end lands your cursor at the end of the search region (instead of the first character by default.

like image 107
Tim Avatar answered Oct 07 '22 15:10

Tim


If you just want to place your cursor after the last character of Fish then you could use

/Fish/e+1

which will place your cursor after the h. (Without the +1 the cursor will end up to the left of the last character.)

If you are particularly interested in placing the cursor after Fish, but only when it appears in "FishTaco" then you can try one of the following options:

You can use

/FishTaco/s+4

and your cursor will end up between Fish and Taco. The /s+4 places the cursor 4 places after the start of the search term.

You could likewise use

/FishTaco/e-3

which will place your cursor 3 places left of the left side of the last (end) character.

You can also use

/FishTaco/b+4 

because /b+4 will be treated as /s+4.

like image 89
ghbarratt Avatar answered Oct 07 '22 13:10

ghbarratt