Hi there!!! This second part of day2 which was taken by kushal on VI.
VI is an editor. Not a GUI but a command line editor and very handy. It was basically made for the UNIX operating system. Since it has a command line interface, there are a whole lotta commands. We were only taught the basics but to even, to rule those basic commands, one needs a lot of practise!! Anyways, am jumping off to what all i learned…(they are all case sensitive):
Some very basic commands like vi <filename> to open or create a new file.
Among other modes, we have an INSERT MODE, which is used to insert some text into the file. Pressing i switches to this mode.
Pressing ESC switches you back to the COMMAND MODE. Then there was a save command :w, exit commands like : x, :e!, :q!. Commands such as h,j,k,l,w,0,$,e are also the also some of the commands to navigate.
The EDITING OPTIONS have commands like a, r,x which work on single characters. Then commands to change lines or words like cw, c$ or C, C0, cc. Delete commands include d, dw, 2dw, d$ or D, dd. Undo action u, ctrl+r. COPY options LIKE y, yy, 2yy, yw, y$, y0, cut as x, paste as p.
. repeats the last action, ~, n~ changes case of letters, adding and joining of lines with o, J.
:set nu! sets line numbers. :n goes to nth line, G takes you to last line.
TO MOVE AROUND THE FILE, ctrl+F to move in forward direction, ctrl+B goes backwards, ctrl+D to go forward half screen, ctrl+U goes backward half screen. +,- takes you to first character of next line and previous line respectively.
SEARCHING is quite easy. U have to simply enter /<text> to search. After this, pressing n takes you to the next occurrence and N takes you to previous occurrence. /enter also takes you to the next match.
SEARCH AND REPLACE is simple. just type in :s/<oldstring>/<newstring> to replace first occurrence. Similarly, :s/<oldstring>/<newstring>/g replaces all occurrences in that line. :1,$s/<oldstring>/<newstring>/g replaces all occurrence of the file. Note here, 1,$ means first to last line. This can also be achieved by entering :%s/<oldstring>/<newstring>/g.
HANDLING MORE THAN ONE FILE:
vi <file1> <file2> <file3> opens the three files. :n takes you to the next file, :last to the last file, :args shows you all argument names, :split and :vsplit splits the screen horizontally or vertically respectively. I liked this part as becomes very easy to work when more than 1 file is to be referred. ctrl+w to move between frames and :e <filename> to open a file.
To use SHELL COMMANDS, type :<command>! Example, :ls!