7

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 bevior 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.

| improve this question | | | | |
  • 2
    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 Dec 19 '18 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 Dec 20 '18 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 Mar 20 '19 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. – klaus Mar 20 '19 at 14:12
1

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]))
        endif
    endif
    call CscopeFind(a:action, a:word)
endfunction

nnoremap  <leader>fg :call TrimJumpListAndCscopeFind('g', expand('<cword>'))<CR>
| improve this answer | | | | |
  • 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. – Stephane Rolland Mar 6 at 16:22

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.