tern_for_vim
tern_for_vim copied to clipboard
Stack/history for TernDef
As a ViM user used to the behaviour of the builtin tags commands (:tag Ctrl-]
, :pop Ctrl-T
), where I can easily return back to previous location after jump to a tag definition, I am missing this feature in Tern.
In an ideal world, Tern would either integrate with built-in tag stack. If that's not possible, then it should at least provide an equivalent of :pop
command, e.g. TernDefBack
.
See also :help tagstack
The Emacs and Sublime Text plugins have this feature. If vim itself has a tag stack, it'd indeed be great if we integrate with that. I unfortunately know very little about vim scripting. Do you maybe want to take a stab at an implementation?
I am not familiar with vim scripting either :(
I did a bit of searching on the internet, and there are apparently two lists maintained by vim: a Tag Stack and a Jump List. The latter works well with the Tern plugin, one can use Ctrl-O
to get back. The drawback is that Jump List is shared with other jump commands like G
or /
, but I find that as an acceptable limitation.
I am proposing to improve the documentation and mention that Ctrl-O
can be used to navigate back from TernDef
jump. What is the best place for that - doc/tern.txt
, README.md
or something else? I am happy to make the change myself.
Link to relevant Vim's docs: :help jump-motions
A quick look over the docs does not show any way to push something onto the tagstack without actually using the tag functionality to jump somewhere. Since the vim docs are not the cleanest docs around, that does not necessarily mean that there is no such functionality. If someone knows a way, a pull request would be very welcome.
I just stumbled upon this issue and have to say that jump lists work well for me with :TernDef
. I can press Ctrl-o
right after the command and it gets me back to the line where I started.
jedi-vim has a goto-definition
command that implements vim's jump stack and allows for using C-t
. It looks like the relevant python code is located here. I haven't taken enough time to understand all of it but hopefully it isn't too hard to port over.
Meanwhile work happens to provide a solution to this problem, I use this work-around:
# file: .vim/ftplugin/javascript.vim
noremap <buffer> <silent><c-]> :<C-u> TagImposterAnticipateJump <Bar> :TernDef<CR>
It is powered by idbrii/vim-tagimposter which was made for this very purpose, given the need has risen since LSP plugins become more popular. Its description says:
Do you have a LSP or other magic that helps you jump to symbols? Are you frustrated that C-t doesn't work with that magic? tagimposter will commit tag forgery for you!
Hope it helps