2

From How do I jump to the location of my last edit?

I can press:

`.

to take my cursor to the position of last edit but:

``

doesn't take me to the last position of my cursor, as it says it should in the question / answer linked above.

There is also `` which will bring you back to where the cursor was before you made your last jump.

5

That link addresses a different use case so it only partially applies.

  1. The "single quote" and "single backtick" marks are not saved between sessions so there's no reason to expect `` to work its magic in your specific example.

  2. `` moves the cursor to the position before the last "jump". Since you are moving your cursor with the arrows or hjkl there's no "jump" involved and thus no reason to expect `` to work its magic in the current session anyway.

  3. Contrary to the "single quote" and "single backtick" marks, the "dot" mark is saved between sessions so

    `.
    

    will effectively work within the current session and in future session.

  4. The "move to last position" mark you are looking for is the "double quote". Like the "dot" mark it is saved between sessions and can be used at any time:

    `"
    
  • So if `" works, why did someone make a plugin to do the same thing? I only ask because I will have to remove this plugin to test :P – Insane Sep 24 '16 at 10:12
  • That plugin appears to do a lot more than the "double quote" mark. – romainl Sep 24 '16 at 10:41
6

(just for completness)

I use this, adapted from Vim's help:

" restore cursor position, if known, and unfold the area
autocmd BufReadPost *
            \ if line("'\"") > 1 && line("'\"") <= line("$") |
            \   silent! exe 'normal! g`"zzza' |
            \ endif

.. so that everytime I open a file, the cursor will be placed at its last known position, the screen is centered, and the area is unfolded.

3

As an alternative I found and downloaded the plugin vim-lastplace.

apt-get install vim-lastplace

It works, but I'm curious as to why

``

doesn't seem to work.

I won't accept this answer because it's a workaround, hopefully someone can explain the question at hand.

  • I'm the author of vim-lastplace. The reason it works is that it does '" which takes you to the last known cursor position in a buffer. – Greg Dietsche Jun 9 '17 at 16:35

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.