Reload tags file Vim
Asked Answered
M

3

24

How do i reload the tags file from within Vim?

Is a restart necessary?

Malang answered 28/1, 2011 at 15:18 Comment(4)
No need to reload it, vim does not keep it in memory. It will rather perform some binary search of the file each time you are looking for a tag.Manet
Days before, I have to do Vim restart to make new tags file take effect. Vim version: 7.2Ghat
Maybe had multiple tags files in different sub directories and were regenerating the wrong one?Moldau
It looks like it isn't stored in memory, but I just came to the same conclusion before realising that I'd spelt my object name wrong (which is why it wasn't finding it)!Aluminate
P
20

According to :help tag-binary-search, the tags file is binary (or linear) searched on each lookup, so there's no need to reload the file:

                                                        *tag-binary-search*
Vim uses binary searching in the tags file to find the desired tag quickly
(when enabled at compile time |+tag_binary|).  But this only works if the
tags file was sorted on ASCII byte value.  Therefore, if no match was found,
another try is done with a linear search.  If you only want the linear search,
reset the 'tagbsearch' option.  Or better: Sort the tags file!

Note that the binary searching is disabled when not looking for a tag with a
specific name.  This happens when ignoring case and when a regular expression
is used that doesn't start with a fixed string.  Tag searching can be a lot
slower then.  The former can be avoided by case-fold sorting the tags file.
See 'tagbsearch' for details.
Pastime answered 29/1, 2011 at 0:3 Comment(3)
i'm sorry, but where is that stated in your quote?Malang
I guess it's implied (why would it binary search in the tags file if the file was loaded into memory at some point?).Pastime
This may have been true in the past, but it's not so for vim 9.x (as per Xavier's answer)Fungus
B
5

As far as I know it is not necessary Vim 7.3 use the tags file as soon as it has been generated.

Baksheesh answered 28/1, 2011 at 15:24 Comment(0)
F
1

I find it helps to just load the tags file in another buffer/tab. Then I can re-load that buffer with :e! to get vim to see my tag updates.

Folderol answered 2/7, 2014 at 14:42 Comment(4)
This worked for me! (probably because I created the tags file after opening vim).Bor
Just tried this, but I made sure the tags file existed before I loaded vim - and then updated the tags file. The result is weird, though - after the tags file is updated, vim then shows me all the results I saw before the tags file was updated, and all the tags after the update. In my case, the edit to the tags file was to add an additional directory to search in, so I ended up with two copies of all the tags that existed beforehand, plus the new tags I was expecting from the new directory I added. ps this is with vim 9.1. So it's a kludge at best I'm afraid - better to just reload vim.Fungus
Actually I just realised I see the same behaviour even without the tags file being loaded, so that doesn't seem pertinent after all.Fungus
Update: until now, I thought using ctrl-] to find a tag would trigger vim to use the tags file. However, I now realise cscope is the culprit (for me). If I issue 'cs reset', the old definitions are cleared. Furthermore this update happens without me needing to first exit vim. I end up with a single updated tag definition. Another oddity is the 'tags' var. Sometimes vim notices the updated tags file when I set this. Setting it to nothing doesn't clear old tags. Summary: if you're having trouble with multiple tag defis, and also use cscope, then that might be the actual culprit, not ctags.Fungus

© 2022 - 2024 — McMap. All rights reserved.