Skip to content

Seattle Unix Group Web Site

Sections
Personal tools
You are here: Home » Meetings » 1995 » Stupid VI tricks

Stupid VI tricks

Block indents

Blocks of text can be indented (moved right) or moved back (move
left).  If you had the following four line in a file and wanted them
to be indented;

Abbet, Joe
Campbell, Bill
Johnson, Pete
Smith, John

Place the cursor on the first line and give the command
4>>
The four lines will be indented by one tab stop.  A . (dot) will
repeat the command and indent another tab stop.
>>
given by itself will indent, by one stop, the current line.

Another way to accomplish the same thing is by marking the beginning
and ending of the indent zone as follows;

Mark the beginning and end of the block or zone with ma and mb and
give the following command;
:'a,'b>
A Tab will be inserted at the beginning of each line and the results will be;
        Abbet, Joe
        Campbell, Bill
        Johnson, Pete
        Smith, John
The command;
:'a,'b>>
will put 2 tabs at the beginning of each line. (>>> will put 3, etc.)
Use
:'a,'b<
to move blocks of text the other way.


Executing Commands from Buffers

Any editing command can be loaded into a named buffer and executed.
This can be very handy for editing a large file where repeated complex
commands are required.  To use this capability, open a line and type
the command using ALL the keystrokes that you would use if giving the
command once.  Example:

:1,/the/The/g
Place the cursor on the line and Yank it into a named buffer (a in the
example) with
"ayy
The line is now in the buffer a.  To execute the line (from the
command mode) give the command
@a
and the command will execute.  The line can be deleted.

In the following examples the symbol ^[ represents the Escape key
which is inserted in the text with a Control-V followed by Escape.
i\fB^[k         (insert, \fB escape, k)
a\fR^[k         (append, \fR escape, k)
i/*^[k          (insert, /* escape, k)
a*/^[k          (append, */ escape, k)

The first two are useful for editing nroff/troff files for inserting
bold font (\fB) and appending regular font (\fR)
The second two are useful for C programmers for inserting and
appending comment delimiters.  Note: The "k" (cursor up one line) is
necessary to back out the [RETURN] that results from the command.

A tricky way to re-format paragraphs within a document would be to
open a file called "fmt", put the following lines in it;

:
nroff | sed -e "/^$/"

Close the file and make it executable with chmod +x fmt.  Place the
file in a directory in your PATH.  Yank the following line into a
buffer f:
:'a,'b!fmt
with
"fyy

Now, mark a paragraph to be formatted with ma at the beginning and
mb at the last line and give the command
@f
The paragraph will be fully formatted.
Created by zoperoot
Contributors :
Last modified 2004-06-20 10:36 AM
« July 2010 »
Su Mo Tu We Th Fr Sa
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
 
 

Powered by Plone

This site conforms to the following standards: