Wednesday, October 9, 2013

Re: cscope best practices

On 2013-10-08, Ethan Hereth wrote:

> On 05/10/13 22:32, Ethan Hereth wrote:

> I also was wondering if there is a easy way to make ctrl-]  also
> jump to a source file (like stdio.h) if the cursor happened to be
> on a filename instead of a valid tag. (Does this even make sense to
> do?)

> Gary, I tried the --extra=+f option to ctags and it seemed to have no effect in
> vim. For example, I rerun ctags with this option, I verify that the tags file
> has changed so the option is being used. Then I have the cursor over, for
> example, main.cpp in my Makefile and I enter ctrl-] and nothing happens. There
> is an entry in the tags file that looks like
>
> main.cpp main.cpp 1;" F
>
> but I am not switched to the file main.cpp. I am aware I can use 'gf' to get
> the same result, I guess I was mainly just curious to see if it could be done
> using the ctrl-] tags shortcut. I would expect it to work but I get nothing.
>
> Any ideas?

Yes. I was wrong about how easy it would be to use Ctrl-] on a file
name. I use various commands to jump to files and I thought that
Ctrl-] was among them, but it turns out it's not.

From ":help Ctrl-]":

CTRL-] Jump to the definition of the keyword under the
cursor.

A "keyword" is not a "file name". A "keyword" usually contains only
alphanumeric characters and underscore, whereas a "file name"
usually may contains those characters plus others such as a period.
See

:help iskeyword
:help isfname

So when you put the cursor over the "main" in "main.cpp" and hit
Ctrl-], that command picked only "main". You could execute

:set isk+=.

and try again and it should work. That's not very practical,
though, since it would prevent Ctrl-] and other commands dealing
with "words" from working as expected in other contexts.

You could instead visually-select the file name and hit Ctrl-] and
it would jump to that file. See

:help v_CTRL-]

Something else you can do is use an approach posted to this list in
2009 by Henrik Öhman: Create a mapping for gf that searches the
current tags file for the file name before searching 'path'. I've
modified his original mappings over the years so that the one for gf
now looks like this.

nnoremap <expr> gf empty(taglist('^'.expand('<cfile>').'$')) ? "gf" : ":tj <C-R><C-F><CR>"

So, if the file name under the cursor (<cfile>) is not in the
current taglist, then jump to it with the normal gf command.
Otherwise, jump to it with the :tjump command.

Regards,
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.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: