Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VI - insert tab on multiple lines

679 views
Skip to first unread message

Dan

unread,
Feb 26, 2002, 9:20:42 AM2/26/02
to
Hello all,

How do I use VI to insert tab on multiple lines.

eg. If I had 100 lines and would like to have each line tab over 3
times.
1
2
3
4
5
.
.
.
99
100

final result:
<tab><tab><tab>1
<tab><tab><tab>2
<tab><tab><tab>3
<tab><tab><tab>4
<tab><tab><tab>5
<tab><tab><tab>....
<tab><tab><tab>99
<tab><tab><tab>100

Is there a quicker way than going to each line and using the "I" than
tab over 3 times?

Al Sharka

unread,
Feb 26, 2002, 9:25:18 AM2/26/02
to
Dan wrote:
>
>If I had 100 lines and would like to have each line tab over 3 times.
> 1
> 2
> 3
> 4
> 5
> .
> .
> .
> 99
> 100
>
> final result:
> <tab><tab><tab>1
> <tab><tab><tab>2
> <tab><tab><tab>3
> <tab><tab><tab>4
> <tab><tab><tab>5
> <tab><tab><tab>....
> <tab><tab><tab>99
> <tab><tab><tab>100
>
> Is there a quicker way than going to each line and using the "I" than
> tab over 3 times?

In vanilla vi:

(the "^I" actually represents a tab character)

:1,100 s/^/^I^I^I/

or relative addressing:

:.,.+100 s/^/^I^I^I/

Or, with your shiftwidth set at the default of 8 and the cursor on
the first line you want to indent:

:sw=8
100>>

or any number of other movement commands combined with the ">" operator.

Peppe

unread,
Feb 26, 2002, 9:36:03 AM2/26/02
to
Thus wrote Al Sharka <ash...@my-deja.com>

> :.,.+100 s/^/^I^I^I/

> Or, with your shiftwidth set at the default of 8 and the cursor on
> the first line you want to indent:

> :sw=8
> 100>>

> or any number of other movement commands combined with the ">" operator.

Or "combine" the two

:.,.+100>>>

Peppe [just for completeness]
--
"Before you criticize someone, walk
Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
c92...@student.dtu.dk (o o) he gets angry, he'll be a mile away
----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson

Matej Cepl

unread,
Feb 26, 2002, 11:19:00 AM2/26/02
to
On Tue, Feb 26, 2002 at 06:20:42AM -0800, Dan wrote:
> Is there a quicker way than going to each line and using the
> "I" than tab over 3 times?

Select all region in rectangular block (Ctrl-V) and then I,
3tabs, ESC. And you are done. No need to fiddle with regexes.

Matej

--
Matej Cepl, cepl...@yahoo.com
138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488

DOS: n., A small annoying boot virus that causes random
spontaneous system crashes, usually just before saving a massive
project. Easily cured by UNIX. See also MS-DOS, IBM-DOS, DR-DOS.
-- David Vicker's .plan

Peppe

unread,
Feb 26, 2002, 11:59:05 AM2/26/02
to
Thus wrote Matej Cepl <cepl...@yahoo.com>

> On Tue, Feb 26, 2002 at 06:20:42AM -0800, Dan wrote:
> > Is there a quicker way than going to each line and using the
> > "I" than tab over 3 times?

> Select all region in rectangular block (Ctrl-V) and then I,
> 3tabs, ESC. And you are done. No need to fiddle with regexes.

That would be a vim solution (5.4 and later, I think, and possible
other clones, too(?)).

In vi you can get lots of beeps with

:set noflash
^V^V^V^V^V^V^V

[:version says "Version SVR4.0, Solaris 2.5.0"]

Somehow it would be nice if people asking questions about vi included
the :version output (or at the first line in the case of a vim
installed as vi). Would save us all some second guessing now that
quite a few systems have a vi clone installed as vi without people
knowing it.

Peppe

Phil Reynolds

unread,
Feb 26, 2002, 12:00:00 PM2/26/02
to
Matej Cepl wrote:
>
> Select all region in rectangular block (Ctrl-V) and then I,
> 3tabs, ESC. And you are done. No need to fiddle with regexes.

vi doesn't have the ability to select a region in the way you describe -
it is a feature of vim.

The simplest way in vi is to use the > command in combination with
either a line count or a cursor motion that defines the area to be
shifted. For instance, if the 100 lines to be shifted are followed by a
blank line (or EOF), then >} will shift those lines by one tab stop
(assuming you have shiftwidth set to the default value 8). Then do ..
to repeat that shift twice.

If there's no obvious cursor motion that defines the region, then
100>>.. is still fewer keystrokes than would be required using the
region select method available with vim.

--
Phil Reynolds http://users.computerweekly.net/fluffer/
Remove "spamaway." if replying by mail

Matej Cepl

unread,
Feb 27, 2002, 10:23:36 AM2/27/02
to
On Tue, Feb 26, 2002 at 04:59:05PM +0000, Peppe wrote:
> That would be a vim solution (5.4 and later, I think, and possible
> other clones, too(?)).

Sorry, I overlooked that it is generic vi question.

Matej

--
Matej Cepl, cepl...@yahoo.com
138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488

Extremism in the defense of liberty is no vice; moderation in the
pursuit of justice is no virtue.
-- Barry Goldwater (actually written by Karl Hess)

0 new messages