Oracle Spin

Day-to-Day Experiences

Archive for the ‘vi’ Category

Commands to change cursor position in vi

Posted by Amin Jaffer on April 6, 2009

h – Left
l – Right
k – Up
j – Down
w – Move forward to beginning of next word
e – Move end of the word
b – Move backward to beginning of the previous word
0 – First position on the line
$ – Last position on the line
^ – First non-blank position on the line
+ or <Return> – First non-blank character on the next line
- – First non-blank character on the previous line
n| – Column n of the current line
H – Top line of screen
L – Bottom line of screen
M – Middle line of screen

Posted in vi | Tagged: , , , | Leave a Comment »

Useful commands in vi to save/quit

Posted by Amin Jaffer on January 28, 2009

There are few commands one can use to save a file n
To save and quit: <esc>:wq
To save (if modified) and then quit, if not modified then does not save quit: <esc>:x (by jwood@opsource.net)
To save (if modified) and then quit, if not modified then does not save quit: <esc>ZZ (by boomslaang@hotmail.com)
To save and continue edititing: <esc>:w
To quit: <esc>:q (Note: You will be able to quit from vi if no changes were made in the file since opening the file or all changes have already been saved, if there changes in the file vi will display the following message “No write since last change..”)
To force quit without saving: <esc>:q!
To save with a different filename: <esc>:w <new filename path can be specified too> (It can be used incases when one doesn’t have permission to overwrite the file or directory is not writable by the user so using this option the changes made by the user can be saved with a different name in a different folder)

Posted in vi | Tagged: , , | 2 Comments »

Useful commands in vi to delete

Posted by Amin Jaffer on January 22, 2009

Useful commands in vi:
To delete lines
One at a time: <esc>dd
n lines at a time: <esc>ndd – where n is the number of lines to be deleted, eg: 3dd would delete 3 lines

To delete all blank lines (lines that don’t have spaces in between): <esc>:g/^$/d
To delete all blank lines that have spaces in them: <esc>:g/^ *$/d
To delete from current cursor position to end of line: <esc>d$ or <esc>D
To delete from current cursor position to beginning of line: <esc>d0
To delete word from current cursor position forward: <esc>dw
To delete word from current cursor position backward: <esc>db
To delete current character: <esc>dl or <esc>x
To delete one character backward: <esc>dh or <esc>X

Posted in vi | Tagged: , , , , | Leave a Comment »