I often want to edit text in say line 200 of a file, but while doing this I need to look at say line 100, so I scroll to line 100. Is there a way to quickly jump back to line 200 after scrolling? Is there a possibility to configure a jump mark that is update with every movement except scrolling?

'' doesn't seem to work.

EDIT: An answer should preferably describe a way to do what I'm asking. That is move to the position the cursor had before scrolling, without having to do anything beforehand.
If you have advice on other ways to solve the general problem, e.g. using splits or setting a mark before scrolling feel free to write a comment.

  • If you navigate to your destination using one or more of the jump commands (', ``, G, /, ?, n, N, %, (, ), [[, ]], {, }, :s, :tag, L, M, H) you can get back to where you started with Ctrl-O.
    – B Layer
    Jun 17, 2019 at 9:37

2 Answers 2


Go back in the same file

Mark your current position with mm , move around, go back with 'm or `m.

Go back to last insert position in the same file


Go back to last insert position and continue in insert mode


Go back accross files

Mark your current position with mM , move around, go back with 'M or `M.

  • This sounds very cumbersome since I would need to do it all the time before scrolling .
    – 0x539
    Jun 14, 2019 at 23:30
  • It's a style, give it some time, your muscle memory will build up, it can also be useful if you wan do some operation related to the marked position.
    – dedowsdi
    Jun 14, 2019 at 23:35
  • I would prefer if vim automatically set a mark when I start scrolling.
    – 0x539
    Jun 14, 2019 at 23:36
  • If that happens, every time you scroll, your last mark will be replaced by current position, it's useless unless you can scroll in one go, but it's common to scroll multiple times before you reach somewhere.
    – dedowsdi
    Jun 14, 2019 at 23:38
  • I meant that the mark should be set only for the first scroll and not updated until there is some movement of a different kind.
    – 0x539
    Jun 14, 2019 at 23:41

First, instead of scrolling, try :100 or 100G; then the ` mark will work.

Second, if viewing multiple parts of the same file, why not :[v]split it? Splits are perfect for multiple views of the same file.

  • I use scrolling because I usually first need to find the location of the part of the file that I'm interested in. So 100G is not an option.
    – 0x539
    Jun 14, 2019 at 23:23
  • @0x539 then try searching or marks?
    – D. Ben Knoble
    Jun 14, 2019 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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