C - Command Line Options C - Editing Commands C - Alphabetical List of Keys ×
C - Command Line Options C - Editing Commands C - Alphabetical List of Keys ×
vi - Command Line Options vi file Invoke vi editor on file vi file1 file2 invoke vi editor on files sequentially Invoke vi editor on file in read-only mode view file vi - Movement Commands Character h, j, k, l Left, down, up, right ( ) Text w, W, b, B Forward, backward by word e, E End of word ), ( Beginning of next, previous sentence }, { Beginning of next, previous paragraph ]], [[ Beginning of next, previous section Lines 0, $ First, last position of current line ^ First char of current line (ignore spaces) +, First char of next, previous line n| Column n of current line H, M, L Top, Middle, Last line of screen Screens CTRL-F, CTRL-B Scroll forward, backward one screen CTRL-D, CTRL-U Scroll down, up one-half screen Z Reposition line with cursor to top of screen Z. Reposition line with cursor to middle of screen ZReposition line with cursor to bottom of screen Line Number CTRL-G Display current line number nG Move to line number n :n Move to line number n G Move to last line in file Marking Position Mark current position as x mx Move cursor to x `x `` Return to previous mark or context 'x Move to beginning of line with mark x '' Return to beginning of line with previous mark Searches /pattern Search forward for pattern ?pattern Search backward for pattern n, N Repeat last search in same, opposite direction /, ? Repeat previous search forward, backward fx Search forward for char x in current line Fx Search backward for char x in current line tx Search forward for char before x in current line Tx Search backward for char after x in current line ; (semicolon) Repeat previous current-line search , (comma) Repeat previous search in opposite direction vi - Cool Things - Putting it together
All editing commands can take most movement commands as objects. For instance, dw deletes a word andd) deletes to the end of the sentence. Most vi commands can be preceded by a count. For example, 5w moves forward 5 words and 5dw deletes to the next five words. Examples: :1,$s/$ /; / This command substitutes the end of line '$' with a ';' from line one to the last line effectively appending a semi-colon to every line. To prefix a line, use a '^' for beginning of line. This substitutes all 'ABC' strings between lines and n with m 'XYZ'. The trailing 'g' makes it global- otherwise only the first 'ABC' in a line would be substituted. Assume the dashes are actually spaces. This command would then substitute lines leading with two or more spaces (the asterisk means 0 or more - a period means 1 occurrence of any character) with one space. This effectively removes tabs or other indentation.
vi - Editing Commands Insert i, a Insert text before, after cursor I, A Insert text at beginning, end of line o, O Open a new line for text below, above cursor Change *Note: r and ~ leave you in command mode r Replace with next typed character ~ Change case of character cX Change text block defined by movement commandX (e.g., cw or c $ ) cc Change current line C Change to end of line R Type over characters s, S Delete character, current line and substitute text Delete, move x, X Delete current, prior character nx Delete n characters dd Delete current line D Delete to end of line dX Delete text block defined by movement commandX (e.g., d/pattern) n dd Delete n lines p, P Put deleted text after, before cursor "n p Put text from delete buffer number n after cursor Yank (Copy) yX Yank text block defined by movement commandX (e.g., y}} or y}) yy, Y Yank current line n yy Yank n lines "a yy Yank current line into named buffera Other . Repeat last edit command u, U Undo last edit; restore current line J, n J Join two lines, Join n lines CTRL-L, CTRL-R Redraw screen vi - Miscellaneous Shell Interaction :sh CNTL-Z :!command :r file :r!command n!!command :m,n!command Setting Options :set option :set no option :set :set all :set autoindent :set number :set showmatch :set showmode :set tabstop= n
Invoke subshell, use exit or ^d to return to editor Suspend process; fg to bring last process to foreground Run command in UNIX and return Read contents of file into current file Read output of UNIX command into current file Send n lines to command and replace from current line Send lines m - n to command and replace Activate Option Deactivate option Display options set by user Shows all current option settings Automatically indents newline previous line Show line numbers Shows the matching left ( or [ when the right one is typed Shows a message indicating when in input mode Sets distance between tabstops to n
:m ,n s/ABC /XYZ /g
:1,$s/^--*/- /
vi - Exit Commands ZZ, :x, :wq Write (save) and quit file :w Write (save) file :w! Write (save) file overriding protection :m ,n w newfile Write from line m - line n as newfile :m, nw >>file Write from line m - line n and append to file :w %.new Write current buffer named file as file.new :q Quit file :q! Quit file (discarding any changes) :e file2 Edit file2 without leaving vi :e! Return to version of current file at time of last write :e + file Begin editing at the end of file :n Edit next file
vi - Alphabetical List of Keys a Append text after cursor A Append text at end of line b Back up to beginning of word in current line B Back up to word, ignoring punctuation ^B Scroll backward one window Change operator C Change to end of current line d Delete operator D Delete to end of line ^D Scroll down half-window e Move to end of word E Move to end of word, ignoring punctuation ^E Show one more line at bottom of window fx Find next x on current line fx Find previous x on current line ^F Scroll forward one window G Go to specified line or end of file ^G Print information about file on status line h Left arrow cursor key H Move cursor to Home position (top left of screen) ^H Left arrow cursor key; backspace key in insert mode i Insert text before cursor (enter Insert Mode) I Insert text after cursor (enter Insert Mode) ^I Unused in command mode; in insert mode, same as TAB j Down arrow cursor key J Join two lines ^J Down arrow cursor key k Up arrow cursor key l Right arrow cursor key L Move cursor to Last position in window ^L Redraw screen m Mark the current cursor position in register (a-z) M Move cursor to Middle position in window ^M Carriage return n Repeat the last search command N Repeat the last search command in reverse direction ^N Down arrow cursor key o Open line below current line O Open line above current line p Put yanked or deleted text after or below cursor P Put yanked or deleted text before cursor or above cursor ^P Up arrow cursor key Q Quit vi and invoke ex ^Q Unused in command mode, in insert mode, quote next char r Replace character at cursor with next character typed R Replace characters ^R Redraw screen s Change the character under the cursor to typed characters S Change entire line t Find character before next x on current line T Find character after previous x on current line char typed u Under the last change made U Restore current line, discarding changes ^U Scroll the screen upward half-window ^V Unused in command mode; in insert mode, quote next char w Move to beginning of next word W Move to beginning of next word, ignoring punctuation ^W In insert mode, back up to beginning of word x Delete character at cursor X Delete character before cursor y Yank (copy) operator Y Make copy of current line ^Y Show one more line at top of window z Redraw the screen and reposition cursor ZZ Exit the editor, saving changes
I:\Joi Documentation\Current\83905755.xls