|
Tips and Tricks
Sorting a block of lines: (courtesy of Dean C.)
mark one end of the block by typing:
ma
move to the other end of the block then type:
!'asort<enter>
Read in the Output:
:r !my_command
This will insert the output of the command on to the next
line of the file that you're editing.
VI File Reversal:
:g/.*/m0
VI File Line Reversal:
g/^/m0
Getting Rid of ^M
:1,$ s'^M''g
VI Copying Between Files
Suppose you want to copy line numbers 1-10 and 23-77
of file A and paste them on file B at the same time, what will you do ??
Place the cursor on line no. 1
Press ESCAPE
Press Shift "(Shift double quotes)
Press a
Press 10yy [the number of lines you want to copy]
Now place the cursor on line no. 23
Press ESCAPE
Press Shift "(Shift double quotes)
Press b
Press 55yy [the number of lines you want to copy]
Now the first 10 lines have been copied in buffer
"a" and next 55 lines have been copied in buffer "b".
Now press " : " (COLON) to get the vi prompt.
Hit e "Destination file name"
Once you enter the Destination file go to the line where you
want the first 10 lines in buffer
"a" to be inserted.
Press ESCAPE.
Press Shift "(Shift double quotes)
Press a.
Press p.
The first 10 lines in buffer "a" gets inserted.
Now go to the line where you want the rest 55 lines in buffer
"b" to be inserted.
Press ESCAPE.
Press Shift "(Shift double quotes)
Press b.
Press p.
The rest 55 lines in buffer "b" gets inserted.
|