USR_26

*usr_26.txt*    For IdeaVIM version 0.12.0.  Last change: 2006 Nov 12

                     IdeaVIM USER MANUAL - by Rick Maddy

                                  Repeating


An editing task is hardly ever unstructured.  A change often needs to be made
several times.  In this chapter a number of useful ways to repeat a change
will be explained.

|26.1|  Repeating with Visual mode
|26.2|  Add and subtract
|26.3|  Making a change in many files
|26.4|  Using Vim from a shell script

     Next chapter: |usr_27.txt|  Search commands and patterns
 Previous chapter: |usr_25.txt|  Editing formatted text
Table of contents: |usr_toc.txt|


*26.1*  Repeating with Visual mode

Visual mode is very handy for making a change in any sequence of lines.  You
can see the highlighted text, thus you can check if the correct lines are
changed.  But making the selection takes some typing.  The "gv" command
selects the same area again.  This allows you to do another operation on the
same text.
   Suppose you have some lines where you want to change "2001" to "2002" and
"2000" to "2001":

        The financial results for 2001 are better 
        than for 2000.  The income increased by 50%, 
        even though 2001 had more rain than 2000. 
                        2000            2001 
        income          45,403          66,234 

First change "2001" to "2002".  Select the lines in Visual mode, and use:

        :s/2001/2002/g

Now use "gv" to reselect the same text.  It doesn't matter where the cursor
is.  Then use ":s/2000/2001/g" to make the second change.
   Obviously, you can repeat these changes several times.


*26.2*  Add and subtract

When repeating the change of one number into another, you often have a fixed
offset.  In the example above, one was added to each year.  Instead of typing
a substitute command for each year that appears, the CTRL-A command can be
used.
   Using the same text as above, search for a year:

        /19[0-9][0-9]\|20[0-9][0-9]

Now press CTRL-A.  The year will be increased by one:

        The financial results for 2002 are better 
        than for 2000.  The income increased by 50%, 
        even though 2001 had more rain than 2000. 
                        2000            2001 
        income          45,403          66,234 

Use "n" to find the next year, and press "." to repeat the CTRL-A ("." is a
bit quicker to type).  Repeat "n" and "." for all years that appear.
   Hint: set the 'hlsearch' option to see the matches you are going to change,
then you can look ahead and do it faster.

Adding more than one can be done by prepending the number to CTRL-A.  Suppose
you have this list:

        1.  item four 
        2.  item five 
        3.  item six 

Move the cursor to "1." and type:

        3 CTRL-A

The "1." will change to "4.".  Again, you can use "." to repeat this on the
other numbers.

Another example:

        006     foo bar 
        007     foo bar 

Using CTRL-A on these numbers results in:

        007     foo bar 
        010     foo bar 

7 plus one is 10?  What happened here is that Vim recognized "007" as an octal
number, because there is a leading zero.  This notation is often used in C
programs.  If you do not want a number with leading zeros to be handled as
octal, use this:

        :set nrformats-=octal

The CTRL-X command does subtraction in a similar way.


*26.3*  Making a change in many files

This information does not apply to IdeaVIM.


*26.4*  Using Vim from a shell script

This information does not apply to IdeaVIM.


Next chapter: |usr_27.txt|  Search commands and patterns

Copyright: see |manual-copyright|