Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Aug 2001 12:58:41 +1000
From:      Tony Landells <ahl@austclear.com.au>
To:        John Fox <jjf@mind.net>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Expanding tabs to spaces within nvi 
Message-ID:  <200108140258.MAA20478@tungsten.austclear.com.au>
In-Reply-To: Message from John Fox <jjf@mind.net>  of "Mon, 13 Aug 2001 13:59:28 MST." <20010813135928.I10559@mind.net> 

next in thread | previous in thread | raw e-mail | index | archive | help
jjf@mind.net said:
> I was just reading some indentation tips on the vim homepage, and ran
> across a setting that causes vim to expand a tab into a sequence of
> spaces.  This is spiffy to me, because I like tabstops of 4, but when
> anybody else gets my code in an editor, it looks funky till they
> change their tabstop setting to match the original.

> Does anybody know if nvi can be made to do this?  I've just finished
> reading the nvi manpage, and it appears to me that the answer to my
> question is "No", but I wanted to be sure. 

It depends...

Handling of tabs/spaces is tied fairly heavily into processing in the
OS/hardware/... that it is seldom straightforward.  Here is my understanding
of general vi behaviour:

There are three variables that affect the use of tabs: shiftwidth (sw),
tabstop (ts), hardtabs (ht).  I'm basically going to forget about hardtabs
because if it's more an "output" option and doesn't have anything to do
with what I understand that you want.

The default setup has sw=8 and ts=8.  That means that when you indent
code it moves by 8 spaces (sw=8), and that the system thinks 8 spaces
is a tab (ts=8), so every time you indent it can replace the spaces
with a tab.

What I think you want to do is change sw=4, so each indent is 4 spaces.
However, each pair of indents is 8 spaces and will be replaced by a tab,
so you get:

	1 indent	4 spaces
	2 indents	1 tab
	3 indents	1 tab + 4 spaces
	4 indents	2 tabs

and so on.

However, when you do this there is some stuff you need to be aware of.
When you indent by typing spaces, they stay spaces.  If you use the vi
commands < and > it will "autoconvert" between spaces and tabs.  Also,
if you use "autoindent", and the insert mode commands ^T and ^D you
get autoconversion between spaces and tabs.

You can get some very strange behaviour when you try to delete characters
that form part of the indentation...

Tony
-- 
Tony Landells					<ahl@austclear.com.au>
Senior Network Engineer				Ph:  +61 3 9677 9319
Australian Clearing Services Pty Ltd		Fax: +61 3 9677 9355
Level 4, Rialto North Tower
525 Collins Street
Melbourne VIC 3000
Australia



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200108140258.MAA20478>