| Book Review | Discussion Page | Request Page | Search Topic | Comment Page | GUIDE TO VI AND EX | ||||||||
|
The VI editor is a screen-based editor used by many Unix users.
The VI editor has powerful features to aid programmers, but many beginning has a tendency
of avoiding VI. Do not let VI editor features overwhelm you. This tutorial is written to
help beginning users get accustomed to using the VI editor, but it also contains sections
relevant to advance users of VI as well. Examples are provided, and the best way to learn
is to apply these examples. You can also obtain a VI guidebook that you can purchase at
your local bookstore
. There's no better way of learning than to experience things
yourself.
|
|||||||||
| To edit a file | vi [ filename ] | |||||||||
| To recover an editing session | vi -r [ filename ] | |||||||||
| Notes on vi commands and modal editing | ||||||||||
|
||||||||||
| Controlling The Screen Display of Your Session | ||||||||||
| Repaint the current screen | {ctrl-l} | |||||||||
| Display line #, # of lines, etc... | {ctrl-g} | |||||||||
| Moving the Cursor | ||||||||||
| Beginning of current line | 0 or ^ | |||||||||
| Beginning of first screen line | H | |||||||||
| Beginning of last screen line | L | |||||||||
| Beginning of middle screen line | M | |||||||||
| Down one line | j, {return}, + | |||||||||
| End of current line | $ | |||||||||
| Left one character | h, {ctrl-h} | |||||||||
| Left to beginning of word | b, B | |||||||||
| Right one character | l, {space} | |||||||||
| Right to end of word | e, E | |||||||||
| Right to beginning of word | w, W | |||||||||
| Up one line | k, - | |||||||||
| Beginning of next sentence | ) | |||||||||
| Beginning of previous sentence | ( | |||||||||
| Paging Through Text | ||||||||||
| Back one screen | {ctrl-b} | |||||||||
| Down half a screen | {ctrl-d} | |||||||||
| Down one screen | {ctrl-f} | |||||||||
| Forware to end of file | G | |||||||||
| Move cursor to specified line | line no. G | |||||||||
| Up half a screen | {ctrl-j} | |||||||||
| Special Pattern Characters | ||||||||||
| Beginning of line | ^ | |||||||||
| End of line | $ | |||||||||
| Any character except newline | . | |||||||||
| Any number of the preceding character | * | |||||||||
| Any set of characters (except newline) | .* | |||||||||
| Searching Through Text | ||||||||||
| Backward for pattern | ?pattern | |||||||||
| Forward for pattern | /pattern | |||||||||
| Repeat previous search | n | |||||||||
| Reverse direction of previous search | N | |||||||||
| Show *all* lines containing pattern | :beg,endg/pattern/p | |||||||||
| :1,$g/compiler/p Will print all lines with the pattern compiler. | ||||||||||
| Substitute patt2 for all patt1 found. | :beg,ends/patt1/patt2/g | |||||||||
| :%s/notfound/found/g Will change all occurences of notfound to found. | ||||||||||
| Creating Text | ||||||||||
| Append text after cursor | a | |||||||||
| Append text after end of line | A | |||||||||
| Insert text before cursor | i | |||||||||
| Insert text at beginning of line | I | |||||||||
| Open new line after current line | o | |||||||||
| Open new line before current line | O | |||||||||
| Take next character literally (i.e. control characters...) and display it | {ctrl-v} | |||||||||
| Modifying Text | ||||||||||
| Change current word | cw, cW | |||||||||
| Change current line (cursor to end) | C | |||||||||
| Delete character (cursor forward) | x | |||||||||
| Delete character (before cursor) | X | |||||||||
| Delete word | dw, dW | |||||||||
| Delete line | dd | |||||||||
| Delete text to end of line | D | |||||||||
| Duplicate text | (use yank and put) | |||||||||
| Join current line with next line | J | |||||||||
| Move text | (use delete and put) | |||||||||
| Put buffer text after/below cursor | p | |||||||||
| Put buffer text before/above cursor | P | |||||||||
| Repeat last modification command | . | |||||||||
| Replace current character | r | |||||||||
| Replace text to end of line | R | |||||||||
| Substitute text for character | s | |||||||||
| Undo your previous command | u | |||||||||
| Transpose characters | xp | |||||||||
| Yank (copy) word into buffer | yw | |||||||||
| Yank (copy) current line into buffer | Y | |||||||||
| Making Corrections During Text Insertions | ||||||||||
| Overwrite last character | {delete} | |||||||||
| Overwrite last word | {ctrl-w} | |||||||||
| Ending Your Editing Sessions | ||||||||||
| Quit (no changes made) | :q | |||||||||
| Quit and save changes | ZZ, :wq | |||||||||
| Quit and discard changes | :q! | |||||||||
| Using ex Commands From Within vi | ||||||||||
| Copy specified lines | :co, t | |||||||||
| Display line numbers | :set nu | |||||||||
| Disable display of line numbers | :set nonu | |||||||||
| Move lines after specified line | :m | |||||||||
| Read file in after specified line | :r filename | |||||||||
| Review current editor options | :set | |||||||||
| Review editor options | :set all | |||||||||
| Set new editor option | :set option | |||||||||
| Write changes to original file | :w | |||||||||
| Write to specified file | :w filename | |||||||||
| Force write to a file | :w! filename | |||||||||
| Some Useful ex commands for use in vi | ||||||||||
| Some useful set options for your ~/.exrc file: | ||||||||||
| :set all | Display all Set options | |||||||||
| :set autoindent | Automagically indent following lines to the indentation of previous line. | |||||||||
| :set ignorecase | Ignore case during pattern matching. | |||||||||
| :set list | Show special characters in the file. | |||||||||
| :set number | Display line numbers. | |||||||||
| :set shiftwidth=n | Width for shifting operators << and >> | |||||||||
| :set showmode | Display mode when in Insert, Append, or Replace mode. | |||||||||
| :set wrapmargin=n | Set right margin 80-n for autowrapping lines (inserting newlines). 0 turns it off. | |||||||||
HOME | DISCUSSION | ABOUT US | RESUME SUBMISSION | BOOK REVIEW | Computer Jobs | Software Info | Tech-Support Directory for Computer Companies |
|
|
Copyright © 1999 www.technologyforall.com. All rights
reserved. |