from __future__ import * 14.11.2003

2003-11-14

Stupid vim tricks

In some projects, like PyObjC, the coding style is to use tabs in C/ObjC code, and spaces in Python. I'm lazy, and haven't set it to do this on load, and I often forget to :set noet (not expand tabs) in vim. The quick trick I use to convert tabs to spaces (or vice versa) is to:
  • set/unset et as appropriate

  • make sure my sw (shiftwidth) and ts (tabstop) are both 4 (this is in my .vimrc)

  • indent the block of code once (this converts, but gives me extra indent) with > in visual mode

  • dedent it with < in visual mode

Voila, the whole mess is now converted from tabs to spaces or vice versa. Here's what I find to be comfortable in my .vimrc (I do have some custom stuff for python, pyrex, coloring, etc. but that's not as important):

set ffs=unix,dos,mac
set ts=4
set bs=2
set et
set sw=4
set sm
set sta
set sts=4
set ai
posted at 12:02:56    #    comment []    trackback []
November
MoTuWeThFrSaSu
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930
Oct Dec

Bob's Rants

XML-Image Letterimage

© 2003-2004, Bob Ippolito