>     I would like to know the command to select multiple lines & move
> them either backward/forward. I need this functionality to make
> indendation in my program.

"backward/forward" are ambiguous terms -- do you mean "up/down in 
the file" or "indent/dedent in the file"?

INDENTING/DEDENTING
====================
You can use the >/< commands to indent/dedent a line, range, 
motion, or as an Ex target.  You can also use control+[t/d] to 
indent/exdent while in insert mode

   :help >
   :help :>
   :help i_CTRL-T

Thus if you have a visually highlighted range (":help V"), you 
can just use

   >

to indent the lines.  Or you can use

   >ip

to indent the "inner paragraph" (using the "ip" text object, 
":help text-objects").  Or, if you want to indent select lines:

   :g/foo/>

will indent all lines matching the pattern "foo" (with an 
annoying stream of messages that I usually suppress with a 
well-placed "sil!" in the command).

Incidentally, indentation behavior is controlled by your 
'shiftwidth' and 'expandtabs' settings.



MOVING LINES UP/DOWN
=====================
To move lines up/down in a file, you can copy (yank) and paste 
them.  Or you can use the Ex ":m"ove command:

   :help :move

For example

   :.,+3m'a

will move 4 lines (the current line and the 3 below it) to the 
location you've marked with the "a" mark.  Any line-reference 
(":help :range") will do, so you can do things like

   :-3,/foo/m1/bar

(take the range from "3 lines above the cursor, through the next 
occurance of 'foo'" and move them to the line after the first 
instance of 'bar' after line #1)  Or even

   :g/foo/m$

will find all lines containing "foo" and move them to the bottom 
of the file.

A side-benefit of the ":m"ove method is that it doesn't tromp 
your scratch yank/delete register.  I frequently use

   :m+

to move the current line below the next one without disturbing my 
registers.

Hope this gives you plenty of ways to do whichever you need, as 
well as showing you some of Vim's power :)

-tim








--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to