Re: VIM and tab to space migration

Discussion in 'Python' started by Robert Montante, May 7, 2004.

  1. >> If you are starting with a file that already contains tabs *and* spaces,
    >> I'd say you have already called upon you the gods of disaster.

    >
    >> [snipped]

    >
    > But I haven't. I did what you suggested, opened a file using ONLY tabs for indentation and VIM stilled inserted spaces when it pressed the tab yet.
    >


    Umm, are you aware of vim configuration files? On Unix the per-user file is ".vimrc" and the global file is $VIM/vimrc ($VIM being vim's installation directory); on Windows the file is %VIM/_vimrc (vim installed in %VIM folder).

    Choose the appropriate config. file, and add commands to force the tab behavior you want. For example:

    :set tabstop=4 " Force tabs to be displayed/expanded to 4 spaces (instead of default 8).
    :set softtabstop=4 " Make Vim treat <Tab> key as 4 spaces, but respect hard Tabs.
    : " I don't think this one will do what you want.
    :set expandtab " Turn Tab keypresses into spaces. Sounds like this is happening to you.
    " You can still insert real Tabs as [Ctrl]-V [Tab].
    :set noexpandtab " Leave Tab keys as real tabs (ASCII 9 character).
    :1,$retab! " Convert all tabs to space or ASCII-9 (per "expandtab"),
    " on lines 1_to_end-of-file.
    :set shiftwidth=4 " When auto-indenting, indent by this much.
    " (Use spaces/tabs per "expandtab".)
    :help tabstop " Find out more about this stuff.
    :help vimrc " Find out more about .vimrc/_vimrc :)

    I think it would be really hard to get Vim to guess whether tabs or spaces are being used in each file (unless you're willing to add a "vim" line to the end of each file), but it's really fairly easy to get vim to force each file into whichever convention you want, as soon as it's edited --- just add the "retab" command to the .vimrc file, and it'll convert automatically.

    (Oh yes, you can also do all the above commands "manually" from the command line, but once you get the ones you want, it's most convenient to put them in .vimrc)

    HTH, -bob,mon.
     
    Robert Montante, May 7, 2004
    #1
    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. tocer
    Replies:
    0
    Views:
    492
    tocer
    Aug 28, 2004
  2. Daniel Folkes

    New to Vim and Vim-Python

    Daniel Folkes, Oct 24, 2007, in forum: Python
    Replies:
    3
    Views:
    553
    projecktzero
    Oct 25, 2007
  3. Guoliang Cao

    vim 6.2 + vim-ruby don't work

    Guoliang Cao, Oct 16, 2003, in forum: Ruby
    Replies:
    1
    Views:
    187
    Brett H. Williams
    Oct 16, 2003
  4. Vincent Foley
    Replies:
    6
    Views:
    159
    Gavin Sinclair
    Apr 10, 2006
  5. lolveley
    Replies:
    3
    Views:
    227
Loading...

Share This Page