When editing a python file in vim;
What is a good way to get all functions or classes listed plus the opportunity to jump to the lines where they are defined?
Function names and definitions may be listed with the -f option to the declare ( typeset ) builtin command (see Bash Builtin Commands). The -F option to declare or typeset will list the function names only (and optionally the source file and line number, if the extdebug shell option is enabled).
Can you tell me bash command to view a function's definition? We need to use the type command or declare command to find and display bash shell function source code under Linux and Unix.
Typically bash functions are permanently stored in a bash start-up script. System-wide start-up scripts: /etc/profile for login shells, and /etc/bashrc for interactive shells.
The compgen is bash built-in command and it will show all available commands, aliases, and functions for you. This command works under Linux, macOS, *BSD and Unix-like system when Bash shell is installed. This command is intended to be used from within a shell function generating possible completions.
A little "manual" but:
:g/def\ .*
will show you the lines and, in normal mode, you can press <line number>gg
to jump to that line.
Building on jan's self found answer below:
A user command GJ (for GrepJump!)
command! -nargs=1 GJ vimgrep <q-args> % | copen
TagList or Tagbar plugin. You will need to have ctags, or exuberant ctags installed.
Excerpt from my .vimrc
:
Bundle "majutsushi/tagbar"
nmap <script> <silent> <unique> <F4> :TagbarToggle<CR>
Got it. If you use the :vim
command, your search is redirected to the quickfixlist. Thus,
:vim /def\ ./ %
:copen
i.e. "do a vim[grep] in the current file" and "open the quickfix window" to jump to the matches will do the task.
Assuming you use ctags or some variant the default :tag foo<Tab>
or :tag <Tab>
command could be enough but you may get tags from other files:
:ilist def .*
is another solution. At the prompt, type :<Number><CR>
:
But I love CtrlP's :CtrlPBufTag
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With