1

When we write code, we usually jump between different parts of the code (using the scrolling or the search functions).

In this situations, on Linux, *vim shifts the cursor to the visible area.

For example, if you are editing on line 10 (but suppose you are not paying attention to the current line number), and you want to just view what you did wrote at line 250 (scrolling the window), the cursor will be shifted near the line 250. If you want to go back (to line 10), and you don't remember the line number, you have to scroll again until you find the line you was at.

Is there a way to leave the cursor fixed (in this case at line 10) when you scroll the window, in such a way that you can jump back to the line just typing a key ?

I took a look at :help scroll and :help cursor, but these help don't say nothing about a fixed cursor option.

This question threat the same problem, but :set mouse=a doesn't do the trick, neither the marks.

5

Vim doesn't remember where you've been in a file unless you made a change there (see :help changelist) or jumped there (see help jumplist). Also, Vim's cursor is always somewhere in a window, that is, in the part of the buffer visible to the user, so you can't leave the cursor on some line and not have it follow you as you scroll elsewhere in the buffer.

The usual solution to your problem is to set a mark (see :help mark-motions) at the original line (e.g., ma), then jump back to that mark when you're done looking elsewhere (e.g., 'a).

  • It is often handy in these situations to use :split or :vsplit – mike Dec 22 '17 at 11:49
2

Vim has this behavior on all platforms that I'm aware of.

Two options:

If you jumped to the new location by searching, just double-tap ' to go back to the line you were on or ` to get right to the character position you were at.

Regardless of how you moved around, Ctrl-O goes to "older" positions and Ctrl-I goes the other way if you go too far.

Read :help jump-motions at a minimum but you'll probably learn a lot if you read the entire :help navigation document.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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