The Python file type plug-in for Vim helps you while developing in Python by providing the following features:
gf
to jump to imported files (searches the Python path).[i
.import
or from
(automatic completion can be disabled if you find it is too intrusive).os
or os.
it would complete os.path
(and others). Be aware that this imports modules to perform introspection and assumes that importing a module does not have serious side effects (although it might, however it shouldn’t).
import
on a from <module> import <variable>
line. (this is not enabled by default because of the side effect issue mentioned above).Experimental features:
To use the plug-in, simply drop the files into your Vim profile directory (usually this is ~/.vim
on UNIX and %USERPROFILE%\vimfiles
on Windows), restart Vim and execute the command :helptags ~/.vim/doc
(use :helptags ~\vimfiles\doc
instead on Windows).
To use the syntax check, please make sure pyflakes is installed. It can be found in most Linux distributions, e.g. on Debian/Ubuntu Linux it can be installed using the following command:
$ sudo apt-get install pyflakes
To enable folds for classes and functions defined without leading whitespace, make sure your Python syntax file uses a match rather than a keyword statement for the def and class keywords.
Change the line to say something like:
:syntax match [group] "\<\%(def\|class\)\>" [options]
I can recommend you Dmitry Vasiliev’s adaptation of the default Python syntax file. In this file you will need to replace the following line:
:syntax keyword pythonStatement def class nextgroup=pythonFunction skipwhite
with:
:syntax match pythonStatement "\<\%(def\|class\)\>" nextgroup=pythonFunction skipwhite
All options are enabled by default. To disable an option do:
:let g:OPTION_NAME = 0
g:python_syntax_fold
option
Enables syntax based folding for classes, functions and comments.
g:python_fold_strings
option
Enables syntax based folding for strings that span multiple lines.
g:python_docstring_in_foldtext
option
To display the docstring of a class/function in the fold text.
g:python_decorators_in_foldtext
option
To display the decorators in the fold text. Currently arguments to decorators are not shown.
g:python_decorator_labels
option
This is a dictionary mapping decorator names to short labels. By default it is empty.
g:python_check_syntax
option
Enables automatic syntax checking when saving Python buffers. This uses pyflakes when available but falls back on the standard Python compiler for syntax checking.
g:python_auto_complete_modules
option
Controls automatic completion of module names after typing import<Space>
or from<Space>
. Enabled by default.
g:python_auto_complete_variables
option
Controls automatic completion of variables after typing a dot or from <module> import<Space>
. Disabled by default.
If you have questions, bug reports, suggestions, etc. you can contact Bart at bart@tarmack.eu or Peter at peter@peterodding.com. The latest version is available at http://peterodding.com/code/vim/python-ftplugin and https://github.com/tarmack/vim-python-ftplugin.
This software is licensed under the MIT license.
© 2013 Peter Odding <peter@peterodding.com> and Bart Kroon <bart@tarmack.eu>.
Last updated Thu May 23 22:10:52 UTC 2013.