The Python file type plug-in for Vim helps you while developing in Python by providing the following features:
- Automatic syntax checking using pyflakes pyflakes.
- Syntax based folding for classes, functions, comment blocks and multi line strings (the fold text includes the docstring if found).
- You can use
gf
to jump to imported files (searches the Python path). - You can search imported files using mappings such as
[i
. - Control-X Control-U completes all available module names.
- Module name completion starts automatically after typing
import
orfrom
(automatic completion can be disabled if you find it is too intrusive).
- Module name completion starts automatically after typing
- Control-X Control-O completes variable names, for example after
os
oros.
it would completeos.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).- You can enable automatic variable completion after typing a dot or if you type a space after
import
on afrom <module> import <variable>
line. (this is not enabled by default because of the side effect issue mentioned above).
- You can enable automatic variable completion after typing a dot or if you type a space after
Experimental features:
- The plug-in now comes with a Python script that uses the AST module in the Python standard library to implement a type inference engine which can be used to suggest completion candidates. The type inference engine has two nice properties that the other completion methods don't have: It has a lot more information to go by and it works by parsing the source code so it's safe to use on code with side effects.
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 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] extsyntax 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
Enables syntax based folding for classes, functions and comments.
Enables syntax based folding for strings that span multiple lines.
To display the docstring of a class/function in the fold text.
To display the decorators in the fold text. Currently arguments to decorators are not shown.
This is a dictionary mapping decorator names to short labels. By default it is empty.
Enables automatic syntax checking when saving Python buffers. This uses pyflakes pyflakes when available but falls back on the standard Python compiler for syntax checking.
Controls automatic completion of module names after typing import<Space>
or from<Space>
. Enabled by default.
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>.