I want to make a mapping that jumps to the file of a mark but on the last visited line. Ideally I would write something like this:

nnoremap z<mark> '<mark>`"

Where z is some command prefix and <mark> is the mark I want to use. However I don't see any way to implement this for all marks. I could manually expand this but that is nasty.

nnoremap zA 'A`"
nnoremap zB 'B`"
nnoremap zC 'C`"
" ...

I was wondering if there is anything nicer then iterating over all marks.

Bonus points if the command can be za and the mark is automatically upper-cased.

  • What's the 'A'" for? marking A and then nnoremap zA 'A works . Doesn't work for ` ma of course. Sorry formatting in comments is horrible
    – Steve
    Commented Mar 12, 2019 at 23:57

1 Answer 1


Try the following:

function MyJumps()
    let chr=nr2char(getchar())
    if chr < 'A' || chr > 'Z'
        return ""
    return "'" . chr . '`"'

nnoremap <expr> z MyJumps()

This maps z to call the function MyJump(). This functions first gets one char of input. If the input is not in the range A-Z it returns an empty string. Else it returns '<char>`".

As the nnoremap is a map-expression, Vim takes the returned characters and executes them.

See :help map-expr


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.