Subject: YA Vim Trick: Indenting an Arbitrary Block

From: Shlomi Fish <[email-masked]>
Date: Wed, 20 Feb 2002 09:00:32 +0200 (IST)

I always had trouble indenting an arbitray block in Vim. The best way I
could find was to count the number of lines in the block (by subtracting
them - %-)) and then to use << or >>. Today, I was browsing the help file
trying to find a way to indent a selection, when I realized the
following method was possible:

1. Go to the end of the block you wish to indent or unindent.

2. Type "m" and then "e". This will set the mark "e" at the end of the
block.

3. Go to the beginning of the block.

4. Type ">`e" to indent or "<`e" to un-indent.

A > or a < expects a motion to come next, and `[mark-letter] goes to the
next mark.

Vim (and possibly vi in general) is so obscure, that one discovers new
ways to do things more efficiently all the time. But I am fond of
technologies that I gradually learn new things in them, so it's OK.

Regards,

	Shlomi Fish

----------------------------------------------------------------------
Shlomi Fish        [email-masked]
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

"Let's suppose you have a table with 2^n cups..."
"Wait a second - is n a natural number?"

---

From: Tzafrir Cohen <[email-masked]>
Date: Wed, 20 Feb 2002 09:08:42 +0200 (IST)

> following method was possible:

Here is a straght-forward way, at least in my vim (6.0)

select the lines (shift-v . 'v' is for selecting by characters. Ctrl-V is
for selecting a block of text) and press >>

-- 
Tzafrir Cohen
mailto:[email-masked]
http://www.technion.ac.il/~tzafrir

---

From: Adi Stav <[email-masked]>
Date: Wed, 20 Feb 2002 12:29:45 +0200

> technologies that I gradually learn new things in them, so it's OK.

Your trick works in vi too. I like vi for the same reason as you, but
I don't think it's obscurity at all; it's not that you discover a new
keystroke or command that makes your life simpler, it's that you 
discover a new way to combine together commands from the relatively 
limited set that you already knew in new ways. I always use the marker
command (with y, d, and so forth), but I never thought of combining it 
with >> (I usually use Viper for code, which does it for me). I like 
systems that are really simple but can be used in very complicated 
ways. Just like UNIX.

> for selecting a block of text) and press >>

That's a vim-only feature that won't work in other vi's. I 
personally consider it a misfeature because it adds nothing 
whatsoever to the marker trick Shlomi described, while creating 
incompatibility and complicating the interface (adds another mode).

I find that the elegance and simplicity of the tools is very 
important to me. I like my tools transparent and understandable, 
and often I prefer not to use tools that do things too obscurely
or too automatically, or that I have no chance to understand 
(e.g., no source code and nontrivial implementation), for as long
as more understandable tools exist, even if they are less 
efficient. Is it only me, or do other members of the list feel 
the same? Or is your choice of, e.g., Linux as a desktop system
based on other factors? I'm suspecting that this might be what 
differentiates a "user-mindset" from a "hacker-mindset" (whether 
the person is a hacker or not). Either person might or might not
be a programmer, but while a user desires functionality only from 
tools, which are blackboxes, and demands elegance only from actual
code they work with, a hacker-minded person makes no distinction
between tools they write and code they work with -- nothing is
truely a blackbox.

---

From: Shlomi Fish <[email-masked]>
Date: Wed, 20 Feb 2002 11:33:55 +0200 (IST)

> for selecting a block of text) and press >>

Maybe it will work, but then again I set my vim 5.x to mswin mode. (I just
like it better this way) I'll try and see what happens.

Regards,

	Shlomi Fish

> To unsubscribe from this group, send an email to:
> [email-masked]
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>