3

I often start editing my code at the top of a deep call chain, and use tags to jump deeper into the call chain. But when going back to where I was before, I often (out of habit) close vim, meaning to open the last file. Except where I wanted to go was actually back to the previous entry in the tag stack, so I have to start over at the top of the call chain and work my way down with tags.

Is there a way to make vim warn before existing if the tag stack is not empty?

I'm thinking something like the warning that you opened multiple files and haven't viewed them all yet: If you try to exit, you get a warning about there being files that you've not viewed, but if you exit again then vim will actually exit.

1 Answer 1

3

There's no built-in option, but you can implement a custom command that either :quits or :pops the last item from the tag stack.

command! QuitOrPop try | pop |  catch /^Vim\%((\a\+)\)\=:E\%(73\|555\):/ | quit | endtry

This attempts to :pop and only :quits if there's a tag stack empty or at bottom of tag stack error message.

You could then use the cmdalias.vim - Create aliases for Vim commands plugin to override the built-in :q (and variants like :wq) with the new :QuitOrPop command.

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.