Skip to content

Commit 6e72b95

Browse files
author
Kenneth Reitz
committed
Merge pull request realpython#1 from mrtazz/python-guide
--- Hey I have written up some basic things how I have configured VIM to develop in Python. I hope syntax and text is ok, wrote it completely on the iPhone (via iSSH) this afternoon :).
2 parents b280249 + 2808cd2 commit 6e72b95

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/starting/dev-env.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,49 @@ Editors
1111
Text Editors
1212
-------------
1313

14+
** VIM **
15+
16+
There exist a couple of plugins and settings for the VIM editor to aid python
17+
development. If you only develop in Python, a good start is to set the default
18+
settings for indentation and linewrapping to values compliant with PEP8::
19+
20+
set textwidth=79
21+
set shiftwidth=4
22+
set tabstop=4
23+
set expandtab
24+
set softtabstop=4
25+
set shiftround
26+
27+
With these settings newlines are inserted after 79 characters and indentation
28+
is set to 4 spaces per tab. If you also use VIM for other languages, there is a
29+
handy plugin at indent_, which handles indentation settings for python source
30+
files.
31+
Additionally there is also a handy syntax plugin at syntax_ featuring some
32+
improvements over the syntax file included in VIM 6.1.
33+
34+
These plugins supply you with a basic environment for developing in Python.
35+
However in order to improve the programming flow we also want to continually
36+
check for PEP8 compliance and check syntax. Luckily there exist PEP8_ and
37+
Pyflakes_ to do this for you. If your VIM is compiled with `+python` you can
38+
also utilize some very handy plugins to do these checks from within the editor.
39+
For PEP8 checking install vim-pep8_. Now you can map the vim function
40+
`Pep8()` to any hotkey or action you want. Similarly for pyflakes you can
41+
install vim-pyflakes_. Now you can map `Pyflakes()` like the PEP8 function and
42+
have it called quickly. Both plugins will display errors in a quickfix list and
43+
provide an easy way to jump to the corresponding line. A very handy setting is
44+
calling these functions whenever a buffer is saved. In order to do this, enter
45+
the following lines into your vimrc::
46+
47+
autocmd BufWritePost *.py call Pyflakes()
48+
autocmd BufWritePost *.py call Pep8()
49+
50+
51+
.. _indent: http://www.vim.org/scripts/script.php?script_id=974
52+
.. _syntax: http://www.vim.org/scripts/script.php?script_id=790
53+
.. _Pyflakes: http://pypi.python.org/pypi/pyflakes/
54+
.. _vim-pyflakes: https://github.com/nvie/vim-pyflakes
55+
.. _PEP8: http://pypi.python.org/pypi/pep8/
56+
.. _vim-pep8: https://github.com/nvie/vim-pep8
1457

1558

1659
IDEs

0 commit comments

Comments
 (0)