Wednesday, October 24, 2012

Re: Indenting

On 25/10/12 04:02, analogsix wrote:
> I created a 'scratch notes file' of VIM commands on gvim on my home pc's Fedora desktop environment.
> When I port this file to my workplace's UNIX environment and launch the notes from VIM, my tab spacing is thrown off. For example, at home my text looks like this:
>
> command1 <- comment blah blah blah
> cmd2 <- comment blah blah blah
> comnd3 <- comment blah blah blah
>
> at work, I get a near similar output when I open the file through VIM. When I open through gvim, I get something like this:
>
> command1 <- comment blah blah blah
> cmd2 <- comment blah blah blah
> comnd3 <- comment blah blah blah
>
> Can you assist please?
>

I think that tab stops are not set to the same width at home and at
work. The responsible setting is 'tabstop' whose standard value is 8. I
recommend keeping hard tabs at 8 characters and using soft tabs (by
setting 'softtabstop' and/or 'shiftwidth') if you want the tab key to
move the cursor by a different amount.

Anyway: To see the file identically regardless of the tabstop setting,
make sure it is edited with 'expandtab':

1) Add a modeline near the top or bottom (no more than 5 lines from the
start or end), see :help modeline -- here are examples:

Type 1 (nothing can follow on the same line)
vim:et
// vim:et
===== vim:et

Type 2 (anything can precede, or, after a colon, follow)
/* vim: set et :*/
<!-- vim: set et :-->
====== vim: set et :======

This line is to tell Vim to ":setlocal expandtab" when editing this
file. It needs 'modeline' on in order to work.

2) Then (once only, and at home where the file looks right)

:setlocal et
:retab!

This will replace all tabs by the proper number of spaces, so you will
see it the same way regardless of where Vim thinks the tab stops are.

See:
:help 'ts' " width of hard tab characters
:help 'et' " if on, hitting <Tab> adds spaces
:help :retab " to change tabs <-> spaces
:help modeline " what a modeline may look like
:help 'modeline' " enable/disable modelines
:help 'modelines' " how far from top/bottom they may be
and possibly
:help 'sts' " soft tab stop
:help 'sw' " width of indenting columns


Best regards,
Tony.
--
Talk sense to a fool and he calls you foolish.
-- Euripides

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: