Create python docstring template using current argument list

I will have a python package coming up soon, so now I am starting to slowly add docstrings to files using vim. So for a function like

def foo(x, y, z=None, **kwargs):

I need to manually dial the following repeatability all day long

""" foo does this stuff.

Parameters
----------
x: 
y:
z: optional
kwargs:

Returns
-------

"""

Is there a way to dynamically generate this docstring pattern by defining some vim macros (which I don't know anything about, so a suggestion on how to get started would be great). Thanks.

+4
source share
4 answers

The author vim-pydocstringkindly added compatibility with Numpy-style docstrings in the package, which now seems to be the best answer to this question.

/ vim

+3

( ); , , .

:abbreviate , , , . , ( ) Vim snipMate ( TextMate); , ; . ( Python) UltiSnips. , . Vim Tips Wiki.

: -, , -, , ; -, . .

+2

- , .

:

  • ,
  • ,
  • ,
  • ,
  • play this macro for each line def.

It will look like this:

qq
yyP
(all your text manipulations)
q
:g/def /normal! @q
+1
source

I am working on a similar thing here https://github.com/Deepakwani93/python_docstring feel free to pull and modify

format.py from this repository adds an sphinx-style document line to all functions (e.g. def x (a, b)) in this py file.

-1
source

All Articles