Spaces and tabs messing up code

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Jan 8 22:20:07 EST 2008


Robert Hicks <sigzero at gmail.com> writes:

> mobiledreamers at gmail.com wrote:
> > my friend uses vim
> > and i use xemacs
> > so our shared python code is a mix of tabs and spaces and it is hard
> > for him to edit it in vim
> >  any idea on how to make it clean
> > convert it all to 4 spaces?
> >  Thanks
> >
> 
> :set ts=4
> :retab!
> 
> :h retab

ASCII TAB stops have only one defined width: 8 columns. Set "tabstop"
to 8.

Instead, use Vim's "softtabstops" feature, where the editor will
backspace over space sequences as though there were "hard tabs" there;
and the "shiftwidth" setting, to determine how many columns the
"indent" and "dedent" commands move text.

Then, use "expandtabs" so that ASCII TABs (and the <Tab> key) are
converted to space sequences. Use "retab" to convert all tabs in the
current buffer.

===== $HOME/.vim/vimrc =====
[...]

" indent shift interval (for shifting text blocks in/out)
set shiftwidth=4

" tab stop interval (for literal ASCII TAB character)
set tabstop=8

" tab stop interval (for pressing <Tab> key)
set softtabstop=4

" expand <Tab> chars to spaces?
set expandtab
=====

The important thing to do, more than a once-off conversion, is to
ensure that your project's "tabs" or "no tabs" policy is automatically
enforced from that point on for all files edited.

-- 
 \              "In the long run, the utility of all non-Free software |
  `\      approaches zero. All non-Free software is a dead end." —Mark |
_o__)                                                          Pilgrim |
Ben Finney



More information about the Python-list mailing list