2

I have setup a tags files in my project directory by running ctags -R ., so then when I put the cursor on a word that is a tag and use the command ], vim "jumps" to that tag. Or more correctly, vim loads the file containing the tag in my current window and moves cursor to the tag definition.
This all works fine, however if I put the cursor on the tag and run the ex command :ptag to open the tag definition in a preview window, I get

E73: tag stack empty

If I then use ] instead, again vim will open the tag fine, however, the original :ptag command is obviously being remembered because when I use the ] command vim will open the tag in a preview window.
I notice vim reports this message regularly. I always just use ] and then vim will open the tag as intended.
The help doesn't give any useful background, from: :h E73

E73
When you try to use the tag stack while it doesn't contain anything you will get an error message.

Its not plugins either, as the exact same behaviour happens when I open the file with:

vim -u NONE -N -U NONE

why do I keep getting this error message when I expect vim to jump to the tag definition?

4

First, the command to jump to a tag is <C-]>, not ].

Second, :ptag doesn't care about the word under your cursor. It works just like :tag but uses the preview window instead of jumping directly to the tag.

:tag and :ptag, without argument, are used to jump to the first tag in the tag stack. You'll obviously get an error if the tag stack is empty, or a semi-useless behavior if it only contains the current tag.

If you want to use :ptag to display the definition of the word under the cursor in the preview window you need to pass that word as argument:

:ptag foo

You can insert the word under the cursor in the command-line with <C-r><C-w>:

:ptag <c-r><C-w>

You can also press <C-w>} to the same effect.

:help :ptag, :help tag-stack.

  • that explains perfectly. thanks. I have read :help :ptag and :help tag-stack but I couldn't see the benefit behind vim's idea of recursively following function definitions and organising the tag stack and the windows as you go along. Therefore I struggled to understand the technical details. It might be worth taking another look though. – the_velour_fog Aug 23 '16 at 7:52

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.