You are on page 1of 2

Vi Editor Commands

Vi Editor has two main modes of operation: 1. Command mode : Initially Vi Editor Opens in Command Mode. To Switch from Insert Mode to Command Mode Press ESC Key. 2. Insert mode : To switch into insert mode, simply press the 'i' key. To Exit Insert Mode Press ESC Key. If you are unsure which mode you are in, press 'ESC'. If you were in insert mode, you will be returned to command mode. If you were already in command mode, you will be left in command mode (possibly with a 'beep', to indicate that you were already in command mode).

Cursor Control Commands


h j k l (or spacebar) w b e ( ) { } [[ ]] 0 $ ^ + or RETURN 0 n| H M L nH nL Ctrl-F Ctrl-B Ctrl-D Ctrl-U Ctrl-E Ctrl-Y z RETURN z. zCtrl-L Ctrl-R /text / ?text ? n N Left Down Up Right Forward one word Back one word End of word Beginning of current sentence Beginning of next sentence Beginning of current paragraph Beginning of next paragraph Beginning of current section Beginning of next section Start of current line End of current line First non-white character of current line First character of next line First character of previous line character n of current line Top line of current screen Middle line of current screen Last line of current screen n lines after top line of current screen n lines before last line of current screen Forward one screen Back one screen Down half a screen Up half a screen Display another line at bottom of screen Display another line at top of screen Redraw screen with cursor at top Redraw screen with cursor in middle Redraw screen with cursor at bottom Redraw screen without re-positioning Redraw screen without re-positioning Search for text (forwards) Repeat forward search Search for text (backwards) Repeat previous search backwards Repeat previous search Repeat previous search, but it opposite direction
Page 1

/text/+n ?text?-n % Ctrl-G nG :n G

Go to line n after text Go to line n before text

Vi Editor Commands

Find match of current parenthesis, brace, or bracket. Display line number of cursor Move cursor to line number n Move cursor to line number n Move to last line in file

Editing
Press ESC Key & then the below mentioned command. dd Delete current line ndd Delete n lines D Delete remainer of line dw Delete word d} Delete rest of paragraph d^ Delete back to start of line dL Delete up to last line on screen dG Delete to end of file u Undo last change U Restore current line J Joins two lines (Current Line & the next line)) rx Replace character with x Rtext Replace text beginning at cursor ~ Reverse case yy Copy current line Paste Copied line below the Current Line p Paste Copied line above the Current Line P Ctrl-U Delete current line ESC End of insert mode :e file2 :e! :e# :n1,n2w >> file :n1,n2w :q :q! :r file :w :w file :w! :w! filename :wq :x ZZ Edit file2 (current file becomes alternate file) Reload file from disk (revert to previous saved version) Edit alternate file Append lines n1 to n2 to file Write lines n1 to n2 to file Quit Quit (even if changes not saved) Insert file after cursor Write file Write file as file, leaving original untouched Write file (ignoring warnings) Overwrite file (ignoring warnings) Write file and quit Quit, only writing file if changed Quit, only writing file if changed

Works in the Insert Mode

File Handling Commands (Press ESC then the command)


To Edit 2nd File while First is still Switch to other opened file for

Page 2

You might also like