albusshin
albusshin

Reputation: 4010

Undo cursor movement in 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?

Upvotes: 9

Views: 5972

Answers (4)

Venkata
Venkata

Reputation: 31

use the shortcut `` to jump back to previous cursor position. But re-using this will not take you back in cursor history but toggles between current and last cursor position.

Upvotes: 1

Ingo Karkat
Ingo Karkat

Reputation: 172520

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>.

Upvotes: 6

Lieven Keersmaekers
Lieven Keersmaekers

Reputation: 58431

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

Upvotes: 7

Ruslan Osipov
Ruslan Osipov

Reputation: 5843

Try CtrlO to go back in cursor history.

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

Upvotes: 16

Related Questions