Re: Spaces and tabs messing up code

Discussion in 'Python' started by Robert Hicks, Jan 9, 2008.

  1. Robert Hicks

    Robert Hicks Guest

    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
     
    Robert Hicks, Jan 9, 2008
    #1
    1. Advertising

  2. Robert Hicks

    Ben Finney Guest

    Robert Hicks <> writes:

    > 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
     
    Ben Finney, Jan 9, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xah Lee
    Replies:
    42
    Views:
    1,387
    Oliver Wong
    May 23, 2006
  2. qwweeeit
    Replies:
    2
    Views:
    652
    qwweeeit
    Dec 14, 2005
  3. Xah Lee

    Tabs versus Spaces in Source Code

    Xah Lee, May 15, 2006, in forum: Python
    Replies:
    135
    Views:
    3,692
    Oliver Wong
    May 23, 2006
  4. rantingrick

    Tabs -vs- Spaces: Tabs should have won.

    rantingrick, Jul 16, 2011, in forum: Python
    Replies:
    95
    Views:
    1,860
    Roy Smith
    Jul 19, 2011
  5. Xah Lee

    Tabs versus Spaces in Source Code

    Xah Lee, May 15, 2006, in forum: Perl Misc
    Replies:
    34
    Views:
    360
    Ben Rudiak-Gould
    May 23, 2006
Loading...

Share This Page