See the following example:

" open a file with 20+ lines.
1gg    " jump to line 1
3gg    " jump to line 3
5gg    " jump to line 5
7gg    " jump to line 7
ctrl+O " back to line 5
ctrl+O " back to line 3
20gg   " jump to line 20
ctrl+O " back to line 3
ctrl+O " back to line 7!!!! But what I expected is back to line 1

I read :h jumplist and know why I get this result. But this behavior is really annoying for me (I use Vim to read c++ code and jump through function call stack frequently), what I want is:

After ctrl+O and make a new jump, vim can erases jump tags that are later than current position in the jumplist.

  • 3
    Not really an answer to your question, but are you already aware of the CTRL-T command? It goes back in the tag stack, which works differently from the jumplist and (I think) closer to what you want.
    – Rich
    Commented Dec 19, 2018 at 16:30
  • @Rich I didn't known ctrl-t before and just tried it, I would say ctrl-t does help a lot, the behavior for tag stack is what I want for jumplist. However, ctrl-t is limited for tag stack, sometimes I stiil have the need for ctrl+O, but each ctrl+] adds an element in jumplist, which makes it annoying to use ctrl+O to go back.
    – Tiny
    Commented Dec 20, 2018 at 17:10
  • I have the same problem. It's really annoying, Please someone can give any help. eg. Clean jump lists after ctrl+o.
    – wllenyj
    Commented Mar 20, 2019 at 12:27
  • This is not possible I think, i.e. there is no settings to achieve that. And this would not be desirable for most people cause we use ctrl+i for going forward in jumplist. And if you just clear the later jumps from the current position, you can't use ctrl+i. So, it will never be the official behavior. But you can maybe use :h getjumplist() to create your own plugin with your wanted behavior.
    – 3N4N
    Commented Mar 20, 2019 at 14:12

2 Answers 2


Neovim has now a jumplist-stack setting that makes the jumplist behave like the tag stack:

set jumpoptions+=stack

For Vim, this is available in version 9.0.1921 or higher.


I had exactly the same problem as yours, which annoyed me years. Now I add a trimjumplist function to vim so I can use below code and it works for me but you will have to compile vim. Hope this will help.

function! TrimJumpListAndCscopeFind(action, word)
    if has('jumplist')
        if exists('*trimjumplist')
            let jl = getjumplist()
            call trimjumplist(len(jl[0]) - str2nr(jl[1]))
    call CscopeFind(a:action, a:word)

nnoremap  <leader>fg :call TrimJumpListAndCscopeFind('g', expand('<cword>'))<CR>
  • 1
    Hi sevenever! On Stackexchange sites, it is good practice to avoid answers of the kind "I have this problem too", and "link only" answers. That's the reason I proposed an edit with the content of the function you have created that is on github. Feel free to add more detailed information. Commented Mar 6, 2020 at 16:22

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.