4

When I start vim and I want to return to the last location in the jump list, I would like to do so with a single <C-O>. However, right now I have to press twice <C-O><C-O> to achieve this.

In order to better understand this, I narrowed down the behavior by deleting viminfo, moving my vimrc away (i.e. vim starts only with defaults.vim), opening a single file and then restarting vim without any argument.

When I then enter :jumps, I get following output

enter image description here

As you can see the first entry in the jump list points to no file and I "move" the current position to this entry when I press the first time <C-O>. This can be confirmed by running :jumps after the first <C-O>.

Vim help says

If the pointer is below the last entry, this indicates that you did not use a CTRL-I or CTRL-O before. In this case the CTRL-O command will cause the cursor position to be added to the jump list, so you can get back to the position before the CTRL-O.

Can someone confirm/explain this to me and maybe point out how this could be resolved?

UPDATE

IMHO if <C-O> is invoked the first time and the newly added entry for return as described in the helpfile is identical to the first entry, it should be skipped and does not need to be added.

Chapter 29 of the user manual suggests to use '0 to return to the last position when you exited vim. I will consider to use this instead. However, <C-O> has the advantage to jump to older entries in the jumplist. Therefore, I still like to know why vim has this behaviour.

Vim version: 8.1.950

6
  • I do '", see :h 'quote, to get to the position I left the file before. Then I can use <C-O> or <C-I> naturally, not requiring to double tap them. Don't know how to solve your problem though, just wanted to share.
    – 3N4N
    Feb 27, 2019 at 10:08
  • check whether you have a mapping starting with <c-o>. Try :map <c-o>
    – Naumann
    Feb 27, 2019 at 14:00
  • This returns No mapping found. BTW, I mentioned in my question that I have removed my own vim config. This could only have been a mapping in a system vimrc or in defaults.vim which I would not have been aware of. Could you try it for yourself? I would appreciate a confirmation by others. I think the comment by klaus is an implicit confirmation by him.
    – Hotschke
    Feb 27, 2019 at 14:21
  • 1
    @Hotschke, yes, I am running nvim v 0.4.0-dev. I have the exact same condition you have. For explicit confirmation.
    – 3N4N
    Feb 27, 2019 at 15:26
  • There has been a new commit to the master branch of neovim which apparently changes the behaviour: jumplist: avoid extra tail entry. It was discussed in issue #9775 and the corresponding PR is #9805. I assume when neovim 0.4 will be released, neovim users will have a different behavior than vim users.
    – Hotschke
    Apr 2, 2019 at 8:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.