Category: vim or vi

Using vi

By peter, September 21, 2009

VIM
Or “vi” (vim being the modern version of vi)


The advantage of VIM over other text editors is that it runs at the lower run levels.

To use “vi” you need to open up a “shel” prompt and type “vi” followed by the name and path of the document you want to edit and press enter.

Example of editing a file using vi

Example of editing a file using vi

Once in “vi” you can use the following to edit the document:

* Press the “Insert” key on the keyboard to edit the document.

Other insert keys are as follows:

a” Inserts after the cursor
A” Inserts at the end of the line
i” Inserts at cursor
I” Inserts at beginning of the line
o” new line below cursor
O” new line above cursor

Once editing is complete you need to press “Esc” then “:wq” to exit and save changes. Or once editing is complete you need to press “Esc” then “:q!” to exit without saving changes.
If you just “viewed” the document without changing anything you can press “Esc” then “:q” to exit.


Some other commands in “vi” are as follows:

NB To use the following commands you need to press “Esc” first.

yy
Yank (copy). Copy a few lines at once by putting the number of lines you want to copy before yy. Eg 4yy

dd
Delete or cut. Put the number of lines to cut or delete before dd.

p
Paste

/wordtosearch
Forward search

?wordtosearch
Backward search

~
Change case

u
Undo

:%s/originalword/newword

Change % to “start line”, “s” to “end line” to change in only certain lines

OfficeFolders theme by Themocracy