Get Python Help in Vim

This post will guide you how to get python library help in vim editor while you are writing the python code. How do I view python help when using vim editor in Linux.

Get Python Help

You can use the pydoc or pydoc3 to get the python help for a given keyword in your system. For example, you want to get help doc for def. Type the following command:

# pydoc def

or

# pydoc3 def

Outputs:

Function definitions
********************

A function definition defines a user-defined function object (see
section *The standard type hierarchy*):

decorated ::= decorators (classdef | funcdef)
decorators ::= decorator+
decorator ::= "@" dotted_name ["(" [argument_list [","]] ")"] NEWLINE
funcdef ::= "def" funcname "(" [parameter_list] ")" ":" suite
dotted_name ::= identifier ("." identifier)*
parameter_list ::= (defparameter ",")*
( "*" identifier ["," "**" identifier]
| "**" identifier
| defparameter [","] )
defparameter ::= parameter ["=" expression]
sublist ::= parameter ("," parameter)* [","]
parameter ::= identifier | "(" sublist ")"
funcname ::= identifier

A function definition is an executable statement. Its execution binds
the function name in the current local namespace to a function object
(a wrapper around the executable code for the function). This
function object contains a reference to the current global namespace
as the global namespace to be used when the function is called.

Get Python Help in Vim Editor

If you want to get pydoc for a keyword in your python code in vim editor, how to achieve it. You need to update ~/.vimrc file for vim editor, and then added the following line into this file. save and close it.

nnoremap <buffer> H :<C-u>execute "!pydoc3 " . expand("<cword>")<CR>

Then you can open one python script and move cursor to a special keyword, and press Shift + H keys in your keyboard. The help doc about this keyword will appear.

You might also like:

Sidebar



back to top