vim question

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Kevin Buettner
Date:  
Subject: vim question
On Oct 15, 1:49am, der.hans wrote:

> if ( $fred ) {
>     # Stoff
>     if ( $anke ) {
>         # Other Stoff
>     }
> }

>
> It'd be nice to choose the 'matching' brace and then operate on those lines.


'%' is a motion command which finds matching parens, braces, etc.
(Note: In the original vi, % only worked on parens.) You could
position the cursor over one of the curly braces and do >% . However,
that usually gets you a little bit more (or less depending upon which
set of braces you choose) than you want. What I usually do is:

    mh
    move cursor to somewhere else
    >'h


The mh command sets a mark called "h". (I think of the "h" as "here". I'll
sometimes use a "t" mark which I think of as "there". This gives me
a quick way to go from here to there.) The >'h command causes all the
lines between the current line and the "h" mark to be shift left by
one shift width. (I always leave my tab stop set at 8. I set my shift
width to various different values depending upon the style of the code
that I'm editing.)

vim has a way to visually select a region that you can operate on. I
don't use vim very often, so take the following with a grain of salt...
Move to the line you want your region to start (or end) on. Hit 'v'.
Then use some arbitrary sequence of motion commands to move to the line
that you want to end your region. As you move, the selected text will
be highlighted. Once you're satisfied with the region, hit '>' (or some
other command.) Voila, your selected region has been shifted.

Kevin