Help: ctags in vim ?

30 views
Skip to first unread message

Kunal Chauhan

unread,
Apr 28, 2020, 9:02:42 AM4/28/20
to vim...@googlegroups.com
Hi Team,

below is my ctags related question in vim :

Q1: I added new functions to some code repo and run the below command
     For generating the ctags I used "ctags -R * " at vim but it is not working.
    still I did not compile my code yet.
Q2: Also my tags folder is not showing by date update in current source directory.

Q3: is ctags require the compilation of code for navigation.

Thanks
Kunal

--
Thanks with Regards!

Kunal Chauhan
Mob:09813614826
Mob:08860397903

Gary Johnson

unread,
Apr 28, 2020, 1:49:34 PM4/28/20
to vim...@googlegroups.com
On 2020-04-28, Kunal Chauhan wrote:
> Hi Team,
>
> below is my ctags related question in vim :
>
> Q1: I added new functions to some code repo and run the below command
>      For generating the ctags I used "ctags -R * " at vim but it is not
> working.
>     still I did not compile my code yet.

The asterisk (*) is not necessary. You can execute just

$ ctags -R

> Q2: Also my tags folder is not showing by date update in current source
> directory.

The tags do not go into a folder; they go into a regular file. If
you have a folder named tags, you will need to either rename that
folder or tell ctags and vim to use a different name for the tags
file.

If you are executing "ctags -R *" or "ctags -R" within vim, try
executing it outside of vim, at the shell prompt. That may let you
see any warnings more easily.

> Q3: is ctags require the compilation of code for navigation.

No, ctags does not require that the code be compiled.

However, some programs generate C source files from files written in
other languages, such as YACC. You may need to compile your code
before ctags will find symbols defined in generated files.

Regards,
Gary

Kunal Chauhan

unread,
Apr 29, 2020, 11:08:45 AM4/29/20
to vim...@googlegroups.com
1. I have added simple a new function to my source dir and running the ctags - R but still at new functions tag is not working.?


2. At each time i opened my source code i need to execute ctags again ?

3. How Can I use  ctags and cscope while I have already opened my file in vim.


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200428174824.GA29220%40phoenix.

Gary Johnson

unread,
Apr 29, 2020, 11:40:44 AM4/29/20
to vim...@googlegroups.com
On 2020-04-29, Kunal Chauhan wrote:
> 1. I have added simple a new function to my source dir and running the ctags -
> R but still at new functions tag is not working.?

I don't know why that is. Ctags usually "just works" without any
fussing so I don't have much experience fixing ctags problems.
I don't have enough information about your situation to make any
further guesses about what might be wrong.

> 2. At each time i opened my source code i need to execute ctags again ?

No. You need to execute ctags again only after you have made
a change to your source code.

> 3. How Can I use  ctags and cscope while I have already opened my file in vim.

First, make sure that the working directory of the current vim
window is the directory that should contain your tags and cscope.out
files. If you started vim in that directory, and you haven't
executed any :cd or :lcd commands, and 'autochdir' is off (the
default), then any window in vim should be using the correct working
directory. You can check with the following command:

:pwd

For ctags, simply execute the following command:

:!ctags -R

For cscope, execute the following two commands:

:!cscope -b -R
:cs add

I think those last two commands are right. I haven't used cscope in
years. I've been using GNU Global instead, and I have plugins that
do a lot of stuff automatically so that I don't have to think about
it.

You can find out more about Vim's cscope commands here:

:help cscope

HTH,
Gary

Kunal Chauhan

unread,
Apr 29, 2020, 12:13:59 PM4/29/20
to vim...@googlegroups.com
If we talk about gnu global is it far better than cscope.

If yes how can i install and use it on my ubuntu machine . 

Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.

Gary Johnson

unread,
Apr 29, 2020, 2:28:26 PM4/29/20
to vim...@googlegroups.com
On 2020-04-29, Kunal Chauhan wrote:
> If we talk about gnu global is it far better than cscope.

It's better at most things; worse at some.

It does a better job than cscope at understanding C++ files. Cscope
apparently understands only C; some C++ constructs confuse it.

There was a bug in cscope some years ago that prevented it from
identifying certain forms of function definitions used by some of my
co-workers. I wrote to the maintainer about it. He tried to fix it
but said that the parser became many times larger and didn't think
the fix was worth that.

Cscope has some features that GNU Global lacks, such as finding
functions that are called by the current function.

GNU Global is almost a drop-in replacement for cscope. There is
a gtags.vim plugin that comes with GNU Global. On Ubuntu, it's
/usr/share/doc/global/examples/gtags.vim.gz. There is also
a tutorial at https://www.gnu.org/software/global/globaldoc_toc.html
that explains how to use GNU Global with Vim, either with or without
the plugin. I recommend reading the tutorial.

> If yes how can i install and use it on my ubuntu machine . 

$ sudo apt install global

In your project directory (wherever you normally execute ctags), to
generate the database:

$ gtags

In vim:

:set csprg=gtags-cscope
:cs add GTAGS

Then use it as you would cscope.

Regards,
Gary

Charles Campbell

unread,
Apr 29, 2020, 2:33:47 PM4/29/20
to vim...@googlegroups.com
Kunal Chauhan wrote:
> 1. I have added simple a new function to my source dir and running the
> ctags - R but still at new functions tag is not working.?
>
>
> 2. At each time i opened my source code i need to execute ctags again ?
>
> 3. How Can I use  ctags and cscope while I have already opened my file
> in vim.
>
1: As I understand things, you haven't compiled your code (yet). Simple
syntax errors, typically caught by a compiler, can occasionally cause
problems for ctags.  Assuming that you've gotten rid of your "tags"
folder so that the ctags can successfully generate a "tags" file, try
running ctags on your C files one at a time.  Does that work (ie. tags
are produced)?  Note that each invocation of ctags will wipe out the
previous work, so this is not a suggestion of how to generate all the
tags you want, rather a way to find what files are causing issues for ctags.

2. Only when you feel the need -- ie. when you've installed new
functions, changed functions' argument lists/types, etc.  Of course,
ctags can tag more than just functions -- local typedefs, etc.

3. When in vim, and editing one of your source files, use  :tag
FUNCTIONNAME , for example, with FUNCTIONNAME being one of your
functions' names.  That will exercise your ctags feature (assuming you
have +tag_binary as a feature).
  For cscope, first check that you have +cscope as a feature (vim
--version).  If you do, then read up on  :help cscope.

Regards,
Chip Campbell
Reply all
Reply to author
Forward
0 new messages