tern_for_vim icon indicating copy to clipboard operation
tern_for_vim copied to clipboard

Stack/history for TernDef

Open bajtos opened this issue 10 years ago • 7 comments

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

bajtos avatar Dec 29 '14 10:12 bajtos

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?

marijnh avatar Dec 29 '14 10:12 marijnh

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 TernDefjump. What is the best place for that - doc/tern.txt, README.md or something else? I am happy to make the change myself.

bajtos avatar Dec 30 '14 13:12 bajtos

Link to relevant Vim's docs: :help jump-motions

bajtos avatar Dec 30 '14 13:12 bajtos

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.

marijnh avatar Jan 20 '15 09:01 marijnh

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.

Slava avatar Mar 16 '15 04:03 Slava

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.

cjbassi avatar Nov 16 '17 04:11 cjbassi

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

PauloPhagula avatar May 02 '19 13:05 PauloPhagula