I like to add marks for move across files but most of the time, I don't care about the line. I want to go on the last position of the cursor.

For example, I have this marks :

mark line  col file/text
 '      1    0 class ContentsController < ApplicationController
 C    350    4 @content.attributes = @content.default_attributes
 M    387    2 app/models/content.rb
 V      3    0 app/views/contents/index.html.erb

So g'M will move to app/models/content.rb on the last cursor position.

1 Answer 1


The mark " indicates the position of the cursor when you last exited a buffer. Using that...

Continue to use your cross-file marks but immediately follow with '" (or `" to restore the column as well as the line):


To make it a bit more convenient you can create a mapping that does the same thing:

:nnoremap <leader>'X 'X'"

If you put this in a function so you can do the double-jump with any mark:

func! Jump2(mark)
    exec "norm! '" . a:mark . "'\""

To run it :call Jump2('X'). A user command and/or mapping can shorten things.

Taking things further, see :help last-position-jump

    This autocommand jumps to the last known position in a file
    just after opening it, if the '" mark is set: >
:au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif

If you instead used BufEnter/BufWinEnter then each time you switch to a different buffer you'll start at the last known position. That may be more than you had in mind but you can easily add logic to the autocommand so it only occurs under certain conditions.

That's just a few things that come to mind. Really, "the possibilities are limited only by your imagination!" ;)

Note: Mark " might not always be set...but from a practical standpoint it usually will be.

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.