You might find following commands handy while working with vi Editor.
1. Write to a New File
You can use :w to save an entire buffer (the copy of the file you are editing) under a new filename
2. Saving part of the file (1 to 20 lines of the file to new file newfile2
:1, 20 w newfile2
3. From line 230 to end of the file would be saved to newfile3
:230,$ w newfile3
4. From current line to line 600 is saved to newfile4
:.,600 w newfile4 Note the dot which indicates current
First character on 1 to 10 lines would be replaced by word “create user” .
:1,10s/^/create user /
To download FREE first 3 chapters of “Unix Handbook for Oracle DBA” and for DBA Tips
6. To append to existing file
You can use the UNIX redirect and append operator (>>) with w to append all or part of the contents of the buffer to an existing file. For example, if you entered:
newfile would contain lines 1-10 and line 340 to the end of the buffer.
7. To insert a character or Change the word
8. Wipe out all changes
What if you want to wipe out all of the edits you have made in a session and then return to the original file? The command:
returns you to the last saved version of the file, so you can start over.
9. Saving into existing file:
Type :w! file to overwrite the existing file, or type :w newfile to save the edited version in a new file.
Insert text i any text you like
Return to command mode [ESC]
Quit vi, saving edits ZZ
10. Single Movements within command mode in vi editor
The keys h, j, k, and l, right under your fingertips, will move the cursor:
left, one space.
down, one line.
up, one line.
right, one space.
Continue to: I/O Redirectors: Standard Input and Standard Output
To download FREE copy of “Recover Database 10 times Faster E- Book” and for DBA Tips