Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo cursor movement in Vim

Tags:

vim

Let's say I have my cursor lying in the code below:

internal static SingleSelectList<Country, int> CreateCountrySingleSelectList(List<Country> countries, List<Airport> airPorts)

And the cursor is in the head of the line. Now I want to move my cursor to the second < of this line of code, which is in the WORD List<Country>, and just doing the key sequence of f<; will bring me there.

But what if I did something wrong by pressing another ;, that will bring me to the next < in the line, which is in the word List<Airport>.

In this situation, how can I get back to the second < using the minimum key strokes?

Is there a fastest way to undo cursor movements, instead of F< or pressing the key hfor a very long time?

like image 876
albusshin Avatar asked Dec 19 '13 17:12

albusshin


3 Answers

Try CtrlO to go back in cursor history.

http://www.rosipov.com/blog/open-previously-edited-file-in-vim/

like image 115
Ruslan Osipov Avatar answered Sep 22 '22 01:09

Ruslan Osipov


The reversible action of ; is , so the answer to your question would be to use , one time.

You can look up what the command does by :h ;

;           Repeat latest f, t, F or T [count] times.   
,           Repeat latest f, t, F or T in opposite direction
            [count] times
like image 36
Lieven Keersmaekers Avatar answered Sep 25 '22 01:09

Lieven Keersmaekers


Contrary to Ruslan Osipov's wrong answer, the f motion does not store the previous position in the jump list (only motions that usually go to non-adjacent lines do).

But nothing prevents you from explicitly setting a jump yourself with m'. Then, you can return to that position via ``, or <C-O>.

like image 33
Ingo Karkat Avatar answered Sep 25 '22 01:09

Ingo Karkat