2

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 Mar 12 at 23:57
2

Try the following:

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

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, privacy policy and cookie policy

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