|======================================================================= | | Vi Commands for Editing a file | |======================================================================= | | Change | Delete | Copy | from Cursor to ... | |----------------------------------------------------------------------- | | cH | dH | yH | top of screen | | cL | dL | yL | bottom of screen | | c+ | d+ | y+ | next line | | c5| | d5| | y5| | column 5 of current line | | 2c) | 2d) | 2y) | second sentence following | | c{ | d{ | y{ | previous paragraph | | c/pattern | d/pattern | y/pattern | pattern | | cn | dn | yn | next pattern | | cG | dG | yG | EOF | | c13G | d13G | y13G | line number 13 | | cw | dw | yw | ... word | | 2cw | 2dw | 2yw | ... 2 words | | 3cb | 3db | 3yb | apply to 3 words back | | cc == S | dd == D | yy == Y | ... line | | c$ | d$ | y$ | ... to EOLN | | c0 | d0 | y0 | ... to beginning of line | | r | x == X | yl or yh | ... 1 character current,before| | R | | | Type over characters | | 5s | 5x | 5yl | ... 5 characters | | C | | | Change current to EOLN | | s == cx | | | Delete char at cursor and | | | | | substitute | |======================================================================= | | Vi Commands for movement within a file | |======================================================================= | | Movement | Action | |----------------------------------------------------------------------- | | h | move 1 character left | | j | move 1 line up | | k | move 1 line down | | l | move 1 character right | | G | move to last line of file | | w == W | move forward by one word | | b == B | move backward by one word | | e E | move to end of word | | ) ( | Beginning of next,previous sentence | | } { | Beginning of next,previous paragraph | | ]] [[ | Beginning of next,previous section | | $ | move to EOLN | | 0 | move to beginning of line | | ^ | move to first character of current line | | + - | move to first character of next,previous line | | n| | move to Column n of current line | | H | move to Top of screen | | M | move to Middle line of screen | | L | move to Last line of screen | | nH | move to n lines after top line | | nL | move to n lines before last line | | ^F | Scroll forward one screen | | ^B | Scroll backward one screen | | ^D | Scroll up one half screen | | ^U | Scroll down one half screen | | ^L | Redraw screen | | ^G | Display current line number and file name | |======================================================================= | | Vi Commands for Moving Text within a file | |======================================================================= | | Moving Text| Action | |----------------------------------------------------------------------- | | p | put text after | | P | put text before (UPPER CASE P) | | xp | transpose to characters | | u | undo last edit | | U | Restore current line | | J | Join two lines in a file | |======================================================================= | | Vi Commands for Adding text to a file | |======================================================================= | | Inserting | Appending | Action | |----------------------------------------------------------------------- | | i | a | Insert at or append after current position | | I | A | Insert at beginning or append at end of line | | o | O | Open new line below, above current line | | 50i* | 25a*- | Insert 50 *'s or 25 pairs of *-'s | |======================================================================= | | Vi and Ex Commands for quitting a file | |======================================================================= | | Quitting | Action | |----------------------------------------------------------------------- | | ZZ | Write file and quit | | :wq | Write file and then quit | | :w! | Write file overriding protections | | :w | Write to file | | :w %.new | Write current pubber named file as file.new | | :3,60w | Write from line 3 - 60 as | | :3,60w>> | Write from line 3 - 60 as append to file | | :q! | Quit without saving changes | | Q | Quit vi and envoke ex | |======================================================================= | | Vi Commands for Storing Deletions in a buffer | |======================================================================= | | | | Last 9 deletes or yanks are stored in buffers labeled 1..9 | | | | To restore them: "#p -- where # is a number from 1..9 | | To scan delete buffers: "1pu.u.u. etc... | | | |======================================================================= | | Vi Commands for Storing Text in a buffer | |======================================================================= | | Using buffers | Action | |----------------------------------------------------------------------- | | "[a..z]yy | Yank line to buffer a..z | | "[a..z]dd | Delete line to buffer a..z | | "[a..z]D | Delete line to buffer a..z | | | | | "[A..Z]yy | Yank to buffer a..z and append to what is there | | "[A..Z]dd | Delete to buffer a..z and append to current | | "[A..Z]D | Delete to buffer a..z and append to current | | "[a..z]p | Put Back from a buffer a..z after | | "[a..z]P | Put Back from a buffer a..z before | |======================================================================= | | Vi Commands for Marking Text within a file | |======================================================================= | | Marking text | Action | |----------------------------------------------------------------------- | | mx | Mark postion where x is any letter | | 'x | Move cursor to first char of line marked by x | | `x | Move cursor to character marked by x | | `` | Return to exact position of previous mark | | '' | Return to beginning of line of previous mark | |======================================================================= | | Searching and Replaceing Text with Ex | |======================================================================= | | Command | Action | |----------------------------------------------------------------------- | | :s/old/new/ | Search for old and replace first occurance with new | | :s/old/new/g | Globally replace old with new | | :s/old/new/gc | Globally replace old with new and confirm | | /pattern | Search forward for pattern | | ?pattern | Search backwards for pattern | | n | Repeat last search in same direction | | N | Repeat last search in opposite direction | |======================================================================= | | Ex Commands for Editing Text within a file | |======================================================================= | | Ex Commands | Action | |----------------------------------------------------------------------- | | :d | delete lines | | :m | move lines Like delete and put in vi | | :co | copy lines | | :t | copy lines | | :n | move to line n | |======================================================================= | | Ex Commands for Manipulating text | |======================================================================= | | | :%d | | Delete all lines in a file | | :%t$ | | | Copy all lines and put at EOF | |======================================================================= | | Ex Address Symbols | |======================================================================= | | Address | Meaning | |----------------------------------------------------------------------- | | 1, $ | All lines in a file | | x,y | Lines x through y | | x;y | Lines x through y, with current line reset to x | | 0 | Top of file | | . | Current Line | | n | Absolute line number n | | $ | Last line | | % | All lines; same as 1,$ | | x-n | n lines before x | | x+n | n lines after x | | -[n] | One or n lines previous | | +[n] | One or n lines ahead | | 'x | Line marked with x | | '' | Previous mark | | /pat/ or ?pat? | Ahead or back to line matching pat | |======================================================================= | | Ex Command List | |======================================================================= | | Command | Description | |----------------------------------------------------------------------- | | ab [string text]| Abbrev - Define string when typed to be translated | | | to text. | | [addr]a[!] | Append text at specified addr, or current addr | | ar | Print the members of the argument list | | [addr]c[!] | Replace the specified lines with text | | [addr]co dest | Copy the lines included in addr to the dest | | [addr]d[buffer] | Delete the lines included in addr | | ie: | | | Mark start text with 'm | | Mark end text with 'n | | :'m,'nd [buffer] Puts 'm to 'n in buffer | | :'m,.d [buffer] Puts 'm to . in buffer | |======================================================================= | | Ex Example Commands | |======================================================================= | | Command | Action | |----------------------------------------------------------------------- | | :3,13d | delete lines 3-18 | | :160,224m23 | move lines 160-224 to follow line 23 | | :23,29co100 | copy lines 23-29 and put after line 100 | | :.,$d | delete from current line to EOF | | :20,.m$ | move lines 20-current to EOF | | :160,224ya | Yank to buffer a | | :pua | Put text from a buffer into current file | |======================================================================= | | Commands to make your life a little easier | |======================================================================= | | Command | Action | |----------------------------------------------------------------------- | | :e | Edit without exiting current editing session | | :e# | Vi remembers 2 filenames, # is the alternate file | | :e!# | Quit current file without saving and edit alternate | | :r | Read in file named | | :r# | e == edit, while r == read in | | :r !command | Read output from UNIX command int current file | | :$r | Read in file and put at EOF this file | | :0r | Read in file and put at beginning of thisfile| | :% | % Stands for current file | | :%s/.*/\U&/ | Change every word in the file to upper case | | :map ^V[END] G | Maps the PC end key to go to bottom of file | | :map ^V[PGUP]^F | Maps the PC Pageup key to scroll forward one page | | :map ^V[PGDN]^B | Maps the PC Pageup key to scroll back one page | | :! command | Give UNIX command | | :sh | Invoke shell | |======================================================================= |