[Gllug] vi indenting

tet at accucard.com tet at accucard.com
Wed Dec 19 09:02:33 UTC 2001


>> Can anyone tell me how to indent several lines at once with spaces in vi?

Simple answer: don't do it! Indenting is done with tabs, The Way God
Intended (tm) :-)

>Type the number of lines to indent, followed by >> to indent by sw spaces
>(where sw is a vi variable - do ":set sw" to see the value and e.g. ":set
>sw=4" to set to 4 spaces).

Actually, that won't work. Unless you have your tabstop set to a value
larger than the amount of whitespace at the beginning of a line, it'll
indent with tabs as much as possible, and use spaces to fill the rest of
the requested indent, thus giving you the worst of both worlds...

	:set ts=200 sw=4

should get it to a state where it'll do what you want (unless you have
lines starting with more than 200 spaces, of course)

>I find it easier to use the visual select in vim, rather than giving a
>count, but each to their own.

I've never understood why people sit and count lines before doing
stuff in vi. That's what marks are there for, so use them! Go to the
first line of the block you wish to manipulate, set a mark ("ma" to
set mark a) You have 26 to play with, labelled a-z, although I've
never needed to use more than 5 at any one time, and that was for a
particularly gnarly macro -- in real life, I can't remember using more
than two concurrently. Then go to the end of the block and perform
your operation between the current position and the mark. In this
case:

	:'a,.>

will indent between the mark and the current line by one shiftwidth unit.
Easy when you know how...

Tet

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list