Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I restore cursor position in Vim as it was before scrolling, selecting or PgUp/PgDn?

I'm tired of searching where I was before I scrolled up to look something at the top.

Are there something like "Prev cursor position" and "Next cursor position" commands (like 'u' and 'R' for regular undo/redo)?

Example: Looking somewhere in the middle of the source file (no editing), then jumping to the top (1G) then failing to find where you was before that. Of course, no marks set. (I know that I can use ":sp" to view several places simultaneously).

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted
  • Ctrlo goes back in jump list
  • Ctrli goes forward in jump list

additionally i would consider to set a mark via m' and when done with scrolling press ''.

share|improve this answer
    
OK, Ctrl+o jumps me to the place where I was editing. How to just to the place where I was looking? I enter "1G" to jump to the beginning and don't know how to jump back (I wasn't editing). Of course mark is not set and I haven't used ":sp". –  Vi. May 21 '10 at 17:17
    
@Vi: no, ctrl-o jumps to where your last jump was (jump list). g; goes where you edited last –  akira May 21 '10 at 17:28
    
1. "vim initrd.txt". 2. 5 times PgDn, 10 times Down. 3. Hold PgUp until hit the top. 4. Ctrl+o? No, It's just jumped to the top. 5. Crtl+o again? It opened some other file... I don't understand what exactly Ctrl+o does, but it doesn't just undo the last cursor movement command. –  Vi. May 21 '10 at 18:32
    
i know, it is using the "jump list" .. :help jumps ... thats why i meant, probably a good idea to use the markers. if you want to jump around in your file and you want to go back to THAT place you started: set a mark, jump around and then come back with ''. –  akira May 21 '10 at 20:05
    
So I can't make Vim replay text and cursor scroll history backwards (I also expected it will handle mouse scrolling in gvim), right? I expected that while holding Ctrl+O is see my text movements reversed, finishing at just opened file positioned in the beginning. –  Vi. May 21 '10 at 22:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.