vim python navigate to imported files
Asked Answered
H

1

8

who is this question may seem silly, but I'm stuck. I write gnuradio application in some python file. In VIM I try to open a file that is imported, for example:

from gnuradio import audio

Let's say I use the function:

audio.sink()

It is possible in vim to quickly get content of

sink()

function? In the manner of command CTRL-] of ctags.

P.s. using Ctags navigation to audio.sink() return me error: tag not found: sink. Using Ctags i can navigate only to local definitions ( not imported ). I check

ctags --list-kinds=python

import option is enabled. Inside tags file i see:

audio   fm_receiver.py  /^from gnuradio import audio$/;"    i
Hsining answered 16/8, 2014 at 22:9 Comment(3)
Ctags should let you jump to a definition anywhere in the project. What version are you using, and how are you invoking it?Musetta
I use exuberant ctags version 5.8. Installed with "apt-get" command. Tags file created from command file using "ctags -R". Then in vim targetting to the "tags" file.Hsining
for make it usable i need to create tags file in each used gnuradio directories (/usr/lib/python2.7/.../gnuradio/audio, ... ) and set this all files to "tags" variable in vim. Is there any plugin that let me don't do this by hand ( more comphortable ).Hsining
P
5

This works fairly quickly, but not exactly like you'd like. You add this line to your .vimrc

nnoremap <C-k> :!ctags -aR /usr/lib/python*/site-packages/<cword><cr>

Then you can hover over the package name gnuradio and press CTRL+K to execute the command which will append that packages source files to your local tags file (vim's default as well). Then you can CTRL+] over the sink keyword to get the function.

Polliwog answered 30/11, 2018 at 4:24 Comment(1)
In my case the file in question is /usr/local/lib/python3.6/dist-packages/webargs/fields.py. So there can be multiple directories to search in. What should we do in this case?Rabah

© 2022 - 2024 — McMap. All rights reserved.