Search code examples
vimctags

Is there a way to have the same tag name in ctags?


I'm looking to write foos,bars,bazs by using a custom language in ctags. It works fine, I can jump to the tag but I'm only allowed to have one unique tag name. I would like to be able to jump through all the tags in different files with a tag named todo1. Ctags is not generating more than one of the same tag name. If I fix this then the next question would be how to jump in vim to the same tag names? I presume :tn probably would not work because I've tried having the same tag names in asciidoc in the past.

For example:

[todo1] This is something important in some/file/path/foo.txt

[todo1] This is something important in another/path/bar.txt

[foo] Some other foo.

My ctags config file is

--langdef=text
--langmap=text:.txt
--regex-text=/^\[([A-Za-z0-9]+)\]/\1/s,section/

In vim I do.

:! ctags -f ~/text/.tags -R ~/text/
:setlocal tags=~/text/.tags

ctags --version

Universal Ctags 5.9.0(b49410f), Copyright (C) 2015 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Dec 16 2020, 11:27:14
  URL: https://ctags.io/
  Optional compiled features: +wildcards, +regex, +iconv, +option-directory, +xpath, +packcc

Solution

  • tags is not generating more than one of the same tag name. If I fix this then the next question would be how to jump in vim to the same tag names?

    I will try to answer the first one.

    Add --fields=+n option (or --fields=+'{line}' option in Universal Ctags) to the ctags command line. That adds a line: field to each tag entry. The line: fields may make the tag entries unique.