Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list all functions defined in a file

Tags:

python

vim

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?

like image 460
Jan Avatar asked Feb 07 '13 08:02

Jan


People also ask

How list all functions in Linux?

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).

How do I see bash functions?

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.

Where are functions stored in bash?

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.

What is Compgen command in Linux?

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.


4 Answers

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
like image 182
minikomi Avatar answered Oct 09 '22 07:10

minikomi


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>
like image 30
Amadan Avatar answered Oct 09 '22 07:10

Amadan


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.

like image 35
Jan Avatar answered Oct 09 '22 08:10

Jan


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:

:tag foo<Tab>

:ilist def .* is another solution. At the prompt, type :<Number><CR>:

:ilist def .*

But I love CtrlP's :CtrlPBufTag:

:CtrlPBufTag

like image 24
romainl Avatar answered Oct 09 '22 08:10

romainl