If you’re a Python programmer who values thorough documentation practices, you might find the vim-pydocstring plugin to be a useful addition to your workflow. This plugin for Vim enables the automatic generation of Python (template) docstrings, which can save significant time and effort compared to manually creating them.
To begin using vim-pydocstring, you need to install it as a Vim plugin. It is
recommended that you use a plugin manager like vimplug and add this line to
your .vimrc
file:
One of the standout features of vim-pydocstring is its ability to insert both
one-line and multi-line docstrings quickly and easily. By moving the cursor to
a def or class keyword line and typing “:Pydocstring,” a docstring template
appears below the line, reducing the time needed to create documentation
significantly. Another way that I prefer to run this plugin is Ctrl _
(ctrl
button and underscore). I achieved that by adding the following command to my
.vimrc
file:
In addition to the core functionality of the plugin, vim-pydocstring allows
customization of various settings to fit your preferences. For instance, you
can adjust the tab and shift widths and choose between different built-in
docstring formats like Sphinx, Numpy, and Google. Personally, I prefer the
numpy style and so I also added the following command to my .vimrc
file:
Once it all set, you can start using vim-pydocstring to generate Python docstrings and enhance the quality of your code documentation. Try it out to see if it can make your workflow more efficient!
Below is the before
and after
demo: