I mean like CTRL-O (repeatedly) but limited to the current file only. Sometimes I check stuff in another file(say using goto definition). And it loads it into the same window.

Still, I want to focus on the current file only.


2 Answers 2


The built-in jump-motions do not differentiate betweeen buffer-local and "remote" jumps, they just move along the jumplist. You need a custom solution that parses and filters the jumplist.

My EnhancedJumps plugin extends the built-in <C-I> / <C-O> commands with variants that move only within the current buffer (this is what you're asking for), or directly jump to the next position in a different buffer.

  • Thanks, it really works. Sometimes I get undefined variable l:output, so maybe there is some sort of incompatibility.
    – eyal karni
    Commented Nov 2, 2018 at 20:32
  • 1
    Ah, great! You can avoid that error with let g:EnhancedJumps_CaptureJumpMessages = 0; it is caused by multiple plugins wanting to use :redir. Commented Nov 3, 2018 at 9:37

FYI I wrote this before the question was updated to make it clear that OP wants to jump to the previous location repeatedly. Given that this answer still addresses the question asked in the subject line and has been upvoted a bit I think it's worth leaving here. Cheers.

Generally speaking, marks are used to jump to previously visited locations in the current file.1 To go back to the last visited line or "the position before the last jump" use either ``, which jumps to the backtick mark, or '', jumping to the tick/apostrophe mark. The difference between these two commands is that the former takes you to the last line and column you had been on while the latter takes you to the first non-blank character of that line.

If you want to see where these marks are currently located you can use :marks, i.e. :marks ' or :marks `

Note that you can actually override these marks, e.g. with m', but I'd wager that very few people do that...the defaults are too useful.

BONUS: Tangentially related to your question is this little goody in help: last position jump. It presents an autocommand that you can utilize that upon opening a file will put the cursor at the position it had last been when you last visited that file. (If you are using source $VIMRUNTIME/defaults.vim in your vimrc file the autocommand is already set up for you.)

1 Marks can also be used to jump file-to-file if uppercase letters are used, e.g. mA and `A

  • Well, thanks. But I want a command that could be used repeatedly which is not the case with ``.
    – eyal karni
    Commented Nov 2, 2018 at 18:56
  • 1
    @eyalkarni Then your question should say so. "Repeatedly" doesn't appear. Perhaps "like ctrl-o" was supposed to imply it but not everyone will read it that way....especially when you say "but .. current file only" in that same sentence.
    – B Layer
    Commented Nov 2, 2018 at 19:16
  • Yes, I will fix that. Sorry.
    – eyal karni
    Commented Nov 2, 2018 at 20:29

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.