Skip python "import" statements in exuberant ctags
Asked Answered
S

2

31

if I have two files

file a.py:

class A():
    pass

file b.py:

from a import A
b = A()

When I use ctags and press Ctrl+] in vim, it redirects me to import statement, not to class definition. In this code all is ok:

file a.py:

class A():
    pass

file b.py:

from a import *
b = A()
Sheol answered 31/8, 2010 at 13:25 Comment(2)
I couldn't tell you how to fix this issue with ctags, but you could try using cscope, or pyscope as a replacement. They integrate with vim nicely.Braggart
pycscope is quite nice, or seems that way. Nice. +1Epizoon
C
59

You can add the following line to your ~/.ctags file.

--python-kinds=-i

to have ctags skip indexing import statements. To see what else you can enable/disable:

ctags --list-kinds=python

Counterespionage answered 8/9, 2010 at 16:52 Comment(1)
This works great! Unfortunately, just adding --python-kinds=-i to the command does not work.Otten
K
1

I use a mapping similar to the following which allows me to choose when there are multiple matches for a given tag:

nnoremap <C-]> :execute 'tj' expand('<cword>')<CR>zv

Also, check the man page for ctags, you might find there is a way to disable this type of tagging.

Kyles answered 1/9, 2010 at 3:25 Comment(1)
Isn't that what g<C-]> does?Quarterback

© 2022 - 2024 — McMap. All rights reserved.