Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move cursor to specific word in current line in Vim

Tags:

vim

Let's say we're currently in this line of code:

readonly L|a|zy<ICountryRepository> countryRepo;

and the cursor is in the position of letter "a", as shown in the code between two "|" symbols.

Now I want to move my cursor to the letter y of the word countryRepo, how can I do that using the minimum key strokes?

(Currently I'm using the key sequence of fyfyfyfy in normal mode ... Kind of stupid)

like image 393
albusshin Avatar asked Dec 18 '13 15:12

albusshin


3 Answers

If you know that it's the 4th y, you can do

4fy

If you know it's the last y in the line, you can do

$Fy

If you don't know at which position it is, you can still do

fy;;;
like image 160
pfnuesel Avatar answered Oct 16 '22 17:10

pfnuesel


I can think of:

4fy 

But you should only do this if you are some strange robot.

/co<cr>fy

Which is one character shorter than your solution, but more easy..

Wfy

Go one WORD forward and then find y.

f>fy

Something like this I would do. Depends on what popups in my mind.

You should look into the easymotion plugin, which helps with arbitrary movements.

EDIT:

easymotion is rather worthless here, it is more useful for jumping to targets further away.

like image 42
Edgar Klerks Avatar answered Oct 16 '22 16:10

Edgar Klerks


In this case, I would use

W

to move to countryRepo, followed by

fy
like image 5
blackbird Avatar answered Oct 16 '22 17:10

blackbird