w move cursor Right one word b Left one word R Overwrite text, pressto end :set nu Display line numbers :set nonu Hide line numbers :set wm=10 Set Wrap Margin 10 spaces from right edge of screen :set wm=0 Turn off Wrap Margin ZZ Write (if there were changes), then quit e Move to end of current word :n Go to line with this number (:10 goes to line 10) H Move to the top line of the screen G Go to last line of the file M Move to the middle line of the screen L Move to the last line of the screen % Move to matching bracket: ( { [ ] } ) c2w is the same sa 2cw, change two words c$ (or C) Beginning with the character under the cursor to end of line, change c^ Beginning with the character under the cursor to start of line, change 6dw deletes six words 6dd deletes six lines d$ (or D) Delete all characters to the end of the line. :5,30d Delete lines 5 through 30 yy Copy (yank) the current line 6yy Copy (yank) six lines, beginning with the current line yw Copy the current word p (or put) Put the text after the cursor position P Put the text before the cursor position :5,10y Copy lines 5-10 . Repeat last command n. Repeat last command n number of times J Join next line to current line u Undo last single change U Restore current line ~ Change letter's case (capital to lower and vice versa) "ayy Copy (yank) a line into buffer a "Ayy Appends to buffer a "a10yy Copies 10 lines into buffer a "a10dd Deletes 10 lines of text into buffer a "ap Put contents of lettered buffer a below the current line Ctrl+ shows the line number of the current line :5,10 co 105 Copy lines 5-10 to the line after 105 :5,20 m $ Move lines 5-20 to end of file :7,300 d Delete lines 7-300 (to buffer) /text Search forward (down) for text (text can include spaces and characters with special meanings.) ?text Search backward (up) for text n Repeat last search in the same direction N Repeat last search in the opposite direction fchar Search forward for a charcter on current line Fchar Search backward for a character on current line ; Repeat last character search in the same direction % Find matching ( ), { }, or [ ] :n1,n2s/old/new/gc n1 is the beginning line, n2 is the ending line number s means to substitute text matching the pattern (old) with text specified by (new) g (global) is optional. It indicates you want to substitute all occurrences on the indicated lines. If you use g, the editor substitutes only the first occurrence on the indicated lines. c (confirm) is optional. It indicates you want to confirm each substitution before vi completes it. type y for yes, n for no or just enter From Command Mode :%s/old/new/g Substitutes old with new throughout the file :.,$s/old/new/g Substitutes old with new from the current cursor position to the end of the file :^,.s/old/new/g Substitutes old with new from the beginning of the file to the current cursor position :& Repeats the last substitute (:s) command :w file Write current file to file :w>>file Append current file to file :5,10w file Write lines 5 through 10 to file :5,10w>>file Append Lines 5 through 10 to file :r file Read a copy of file into current file :!ls See a list of files in your current directory :n file Read a file onto current Vi session :set all Display all options :set Display current settings of options :set nooption Unset [option] :set ai Set Auto Indentation during text entry :set ic Set Ignore Case during searches :set nu Show line Numbers :set sm Show Matching ( or { when ) or } is entered :set wm=10 Set Wrap Margin 10 spaces from right edge of screen :map @ :!dir ctrl+v , when @ is hit (when vi in command mode)it is the same as :!dir is entered, which results in invoking dir command from vi :map @ :!dir ctrl+v same as above. :ab UW UniversityofWashington in insert mode,whenever UW is typed in,Universityof Washington will appear. vi file1 file2 vi two (or more) files at the same time From Command Mode :n Move to file2 from file1 :rew Rewind back to file1 :e! Restore original file1 file2 (start all over) ZZ Save and quit file. (Must be done for each file.) :1,$> Move entire file 1 shift width (eight spaces) to the right :1,$< Move entire file eight spaces to the left :%s/^/ /g Insert any number of spaces at the beginning of each line in the entire file. Simply press the space bar the desired number of times. :20>> Moves next 20 lines over 1 shift width. :sh Return to the shell to enter a number of shell,DOS commands without leaving vi. ctrl+z Minimize the window d Scroll down one-half screen u Scroll up one-half screen f Scroll forward one full screen b Scroll backward one full screen % in ex-mode (pure ex mode), % is current file name # previously edited file name :!cmd in ex-mode, to run shell command [cmd] :!cc % compile the current file with cc write a config file like config.v to customize your vi. suppose config.v contains: set noerrorbells after open vi, at command mode, issue :so config.v . in command mode, is the current line :!! to repeat last shell command issured within vi :map @ :w^[:!perl.pl a.pl^M map @, means hitting @ will save file(a.pl), then run this perl script (a.pl), ^[type in as ctrl+v, then type in Esc key. ^M: type in as ctrl+v, then type in enter key :edit another_file to edit another file another_file without exiting current vi session. This is very convient to copy something from another_file to current file being edited by vi shift Q to go to pure ex-mode, causing vi not to see current mapping and abbreviations (that is unmap all and unabbr all). Then under pure ex-mode (this mode has :), issue vi to go back to vi session. y/; find ; on current line, then copy upto (not including); y) copy to the end of the line ma in command mode, mark current cursor position as a `a go to the position previously marked as a 'a to to the line prevously marked with a :map @ G:1^M'a go to the end and then start of the file then go to the line marked with a, useful if you want to a specific location with a full screen of source code after issue cc command y'a to copy down/up to the line marked with a from current line "ay'a to copy down/up to the line marked with a from current line into named buffer a unm @ to unmap @ unabbr @ to unabbreviate @ @a to execute the command stored with the named buffer a, suppose name buffer a contains following (which could be in your file): :1, 10s/^/ / then @a will add four character space to the beginning of each of lines 1, 10 if named buffer a contains H!Lsort then @a will sort everything from the start to the end of the screen :map z iif () { } else { }^[kkkllll to insert: if () { } else { } and move cursor to the right paranthesis, when you hit z in command mode >> shell command for append a file to another file, like cat file1>>resultFile echo>>file_name shell command to write input [from screen] to file_name :args show argument list including names of files being edited by vi : repeat (or continue) last ex-mode command (which begins with :) `` to go back to original position [[ to go to beginning to section ]] to go to end of section