Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim keep cursor location while scrolling

Tags:

vim

Is there a way to keep the cusror location off-screen in Vim / gVim while scrolling? Similar to many Windows editors.
I know about marks, and do use them. I also know the '.' mark (last edit location), But looking for other ideas. I'm asking this because sometimes i want to keep the cursor at some location, scroll to another place using the mouse-wheel, and then just press an arow key or something to get me back to that location.

like image 948
Ayman Avatar asked Mar 25 '09 06:03

Ayman


1 Answers

No. vim is a console application, so it doesn't really make sense to have the cursour off-screen (it's possible, but would just be confusing)

An alternative solution, to paraphrase posts from this thread from comp.editors:

Ctrl+o goes to the previous cursor location, Ctrl+i goes to the next (like undo/redo for motions)

Marks seem like the other solution..

Also, use marks. Marks are named by letters. For instance typing ma remembers the current location under mark a. To jump to the line containing mark a, type 'a. To the exact location use `a.

Lower-case-letter marks are per-file. Upper-case-letter marks are global; `A will switch to the file containing mark A, to the exact location.

Basically ma, move around, then `a to jump back.

Another option which Paul suggested,

gi command switches Vim to Insert mode and places cursor in the same position as where Insert mode was stopped last time.

like image 96
dbr Avatar answered Sep 19 '22 08:09

dbr