vi editor

9
VI EDITOR VI EDITOR IS THE KING OF ALL EDITORS

Upload: er-mittinpreet-singh

Post on 15-Apr-2017

439 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Vi editor

VI EDITORVI EDITOR IS THE KING OF ALL EDITORS

Page 2: Vi editor

Why vi!!!!

In unix there are many editors but among them ed, ex, and vi is mostly available in every Unix version.

Ed and ex editors are basically line editors which means that ed assigns line numbers to the lines in the file;every time you do something, you must tell ed which line or lines to do it to. If you have used edlin program in DOS, ed should look familiar.

Compared to ed or ex the vi text editor is head and shoulders above them in almost every way. It is a screen editor rather than a line editor;it shows you as much of the file as it can fit on the screen. You don’t have to beg it to display bits and pieces of your file.

Page 3: Vi editor

There are several disadvantages of using vi Editor The user is always kept guessing. There are no self-explanatory

error messages. If anything goes wrong no error messages appear, only the speaker beeps to inform you that something went wrong.

There are three modes in which the editor works. Under each mode the same keypress creates different effects. Hence Meaning of several keys and their effects in each mode have to be memorized.

Vi is case sensitive. A ‘h’ moves the cursor one position to the left whereas a ‘H’ positions it at the top left corner.

Page 4: Vi editor

Modes of Operation

The vi program has three modes of operationa) Cmd Mode : In this mode all the keys pressed by the user are

interpreted to be editor commands. For ex: if you hit a ‘h’ the cursor is moved one position to the left. In command mode the keys that are hit are not displayed on the screen.

b) Insert mode: This mode permits insertion of new text. Each of these operations can be performed only after changing over from the command mode to insertion mode.

c) Ex Cmd Mode: This mode permits us to give Commands at the command line. The bottom line of the Vi screen is called the Command Line.

Note: If you are not sure which mode you are in, press the Esc key twice,and then you'll be in command mode.

Page 5: Vi editor

Interaction with Vi Editor

$vi filename If we will not give filename then at ex cmd line we have to give the

filename. After typing the contents in the file we will use shift + zz or ZZ to

save the file. To edit your text you need to move the cursor to the point on the

scree where you will begin the correction. This is easily done with 4 keys “ ‘h’ ‘j’ ’k’ ‘l’ ”.

How to delete Text If you want to delete a character, move the cursor to that character and

press the ‘x’. If you want to delete three characters press ‘x’ three times or press 3x.

Page 6: Vi editor

Different combination:ZZ Exit it, saving changes t<x> up to <x> forwardQ Enter ex mode T<x> Back up to <x><ESC> End of insert <x>| Go to column <x>:<cmd> Execute ex command w,W Forward one word:!<cmd> Shell command b,B back one word^g Show filename/size e,E End of word^f Forward one screen ^h Erase last character^b back one screen ^w Erase last word^d Forward half screen ^? Interrupt^u Backward half screen ~ Toggle character case<x> G Go to line <x> a append after/<x> search forward for <x> I,I Insert before?<x> search backward for <x> A Append at the end of line^r Refresh screen dd Delete line

Page 7: Vi editor

Ex Mode Commands q Quit set <x>

Enable option q! Quit, discard changes set no<v> Disable option r <f> Read in file <f> set all Show all options sh Invoke shell vi Vi mode wq Write and quit w <f> Write file <f> w! <f> Overwrite file <f>

Page 8: Vi editor

Sort commandSyntax :

$sort [options]… [FILE]…-b, --ignore-leading-blanks Ignore leading blanks.

-d, --dictionary-order Consider only blanks and alphanumeric characters.

-f, --ignore-case Fold lower case to upper case characters.

-g, --general-numeric-sort Compare according to general numerical value.

-i, --ignore-nonprinting Consider only printable characters.

-M, --month-sort Compare (unknown) < `JAN' < ... < `DEC'.

-h, --human-numeric-sort Compare human readable numbers (e.g., "2K", "1G").

-n, --numeric-sort Compare according to string numerical value.

-R, --random-sort Sort by random hash of keys.--random-source=FILE Get random bytes from FILE.-r, --reverse Reverse the result of comparisons.

--sort=WORD Sort according to WORD: general-numeric -g, human-numeric -h, month -M, numeric -n, random -R, version -V.

-V, --version-sort Natural sort of (version) numbers within text.

Page 9: Vi editor

Other options of Sort command--batch-size=NMERGE Merge at most NMERGE inputs at once; for more use temp files.

-c, --check, --check=diagnose-first Check for sorted input; do not sort.

-C, --check=quiet, --check=silent Like -c, but do not report first bad line.

--compress-program=PROG Compress temporaries with PROG; decompress them with PROG -d.

--debug Annotate the part of the line used to sort, and warn about questionable usage to stderr.

--files0-from=F Read input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input.

-k, --key=POS1[,POS2] Start a key at POS1 (origin 1), end it at POS2 (default end of line). See POS syntax below.

-m, --merge Merge already sorted files; do not sort.

-o, --output=FILE Write result to FILE instead of standard output.

-s, --stable Stabilize sort by disabling last-resort comparison.

-t, --field-separator=SEP Use SEP instead of non-blank to blank transition.

-T, --temporary-directory=DIR Use DIR for temporaries, not $TMPDIR or /tmp; multiple options specify multiple directories.

--parallel=N Change the number of sorts run concurrently to N.

-u, --unique With -c, check for strict ordering; without -c, output only the first of an equal run.

-z, --zero-terminated End lines with 0 byte, not newline.

--help Display a help message, and exit.

--version Display version information, and exit.