Welcome aboard!
> I would like to ask you how to re-indent old files I edited in
> TextMate. They use spaces instead of tabs, set to two spaces.
> Now I have some rows rightly indented to the Vim default and some
> stick to two spaces like in TextMate.
> Which is the command to reformat them?
The settings are controlled by various correlated settings:
:set ts=2 sw=2 et
which you can learn about at
:help 'tabstop'
:help 'shiftwidth'
:help 'expandtab'
:help :retab
Setting the 'tabstop' to 2 changes your tab-stops to
2-visual-spaces-per-tab. I like to keep my 'shiftwidth' in sync
with my 'tabstop' setting just so things like the ">"/"<"
operators and ^D/^T work as expected in insert-mode.
If Vim is inserting real tabs instead of expanding spaces, the
'expandtab' setting will change future insertions. To change
past insertions of real-tabs, once you have the above ":set"
command, you can then use ":retab" to force vim to change
existing tabs to the spaces you defined.
> And, which are the settings to add to my .vimrc file?
You should be able to just add the above "set" (minus the colon)
to your vimrc to get this behavior by default. Alternatively, if
you allow modelines, you can include a modeline in your files
that specifies these settings:
:help modeline
:help 'modeline'
which would allow you to put something like
/* vim: set tw=2 sw=2 et */
at the top or bottom of your file, and vim will set them on a
per-file basis.
Hope this helps,
-tim
I have put a new section ("Different settings for different file
types") in this tip:
http://vim.wikia.com/wiki/Indenting_source_code
Would Vimmers please have a look at the above and let me know if
any changes should be made because I find it incredibly
irritating that we do not have an easily-accessible and
"correct" set of answers to good questions such as the above.
BTW, for all new users:
Please bottom post on this list. Quote a small (relevant) part
of the message you are replying to, and put your text underneath.
See
http://groups.google.com/group/vim_use/web/vim-information
John
autocmd FileType perl :set ts=4 sw=4 et tw=78
autocmd FileType xml :set ts=2 sw=2
autocmd FileType html :set ts=2 sw=2 et tw=78
Those are just examples...you can do your own. :-)
Or rather, put them into vim-scripts in ~/.vim/after/ftplugin/ (on Unix)
or in ~/vimfiles/after/ftplugin/ (on Windows):
--- ftplugin/perl.vim
setlocal ts=4 sw=4 tw=78 et
--- ftplugin/xml.vim
setlocal ts=2 sw=2 tw=0 noet
etc. (Create the files and/or directories if they don't exist yet.)
It is important to use ":setlocal" rather than ":set", to avoid changing
the setting on other files being edited in parallel.
Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
171. You invent another person and chat with yourself in empty chat rooms.