[Tutor] Tabbing with vi (vim) and Python
Scot Stevenson
scot@possum.in-berlin.de
Mon Feb 17 06:15:04 2003
Hello Tim, Paul:
> I'm sure that's so, but I'm not one of them <wink>. A quick search via
> Google suggested that Python vim users do
>
> :set expandtab tabstop=4 shiftwidth=4
>
> but it's all gibberish to me.
Over the last ten years, I have found that you can do everything with vim, you
just have to be willing to figure out the docs, which are somewhat daunting
at times. My life with Python has been pure joy with the following options in
~/.vimrc :
set textwidth=75 - Wrap after 76 Chars (could probably be 77, too)
set autoindent - Automatically indent
set tabstop=4 - A tab is four chars wide
set expandtab - Turn Tabs into whitespace
set shiftwidth=4 - Indent width for autoindent
filetype indent on - Indents depending on filetype
The last line is somewhat magical, as it lets you edit Python with four spaces
and C with eight spaces to a tab; you might not need the other entries with
this. Note I use a four-space-tab for everything, YMMV. There is also a
system-wide file called "/etc/vimrc" (at least with SuSE 8.1) where things
are set up for all users; one line I have there that you might want to put in
~/.vimrc if it isn't in your version is
syntax on
which starts syntax highlighting.
These are nice commands:
CTRL-D - In insert mode, go back one indent level
CTRL-T - In insert mode, go forward one indent level
To move a whole Python block one indent level, mark the block visually (with
'v') and then use the '<' or '>' key to move it to the left or write.
Oh, and a nice command to know is:
:%retab - Convert all tabs depending on "expandtab"
Manditory comment on the Vi-Emacs-War: If you are a touch-typist, go with vi,
nothing is better: You will only have to learn one editor your whole life,
and with a bit of practice, you'll slaughter everybody else on speed. If you
hunt-and-peck with two fingers, you're might just possibly be better off with
Emacs - I think somebody is working on a Emacs that uses Python as a
scripting language instead of Lisp.
At least, somebody /should/ be working on a Python version of Emacs...
Y, Scot
--
Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany