Vi Reference

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

vi editor basics

a A i I o O w W b B e E x X D dw ndw dd ndd dG R r C s J xp ~ :w :w new_file :w! existing :wq ZZ :q! G 1G :21 21G /string ?string n N Append text after cursor. Append text at the end of the line. Insert text before the cursor. Insert text at the beginning of the line. Open a new line below the cursor. Open a new line above the cursor. Move forward one word. Move forward one word past punctuation. Move backward one word. Move backward one word past punctuation. Move forward at end of word. Move forward at end of word past punctuation. Delete character at cursor. Delete character left of cursor. Delete line to right of cursor. Delete word right of cursor. Delete n number of words. Delete line containing the cursor. Delete n lines. Delete to end of FILE. Overwrite characters on line. Replace one letter only. Change from cursor to end of line. Substitute string for character. Join current line and line below current line. Transpose/switch letters. Change case of letter. Save changes. Save with name new_file Overwrite existing file existing Save changes and quit vi. Save changes and quit vi Quit without saving. Go to last line. Go to first line of file. Go to line 21. Go to line 21. Search forward for string Search backward for string Find next occurrence of string Find previous occurrence of string h j k l H M L CTRL-f CTRL-d CTRL-b CTRL-u :5,10d :1,3co 5 :4,6m 8 cw ncw nyy Y p P :r insert_file :n r insert_file u U :u :set nu :set nonu :set ic :set noic :set list :set nolist :set showmode :set noshowmode CTRL-L Move cursor left (left arrow; backspace) Move cursor down (down arrow) Move cursor up (up arrow) Move cursor right (right arrow, spacebar) Move to top of screen. Move to middle of screen. Move to bottom of screen. Page forward one screen. Scroll down one-half screen. Page back up one screen. Scroll up one-half screen. Delete lines 5 through 10. Copy lines 1 to 3; put after line 5. Move lines 4 to 6 to line 8 Change word. Change n words. Yank n lines (copy). Yank current line. Put yanked/deleted line(s) below current line. Put yanked/deleted line(s) above current ilne. Insert insert_file below the current line. Insert insert_file after line number n.

Undo previous command. Undo all changes to current line. Undo previous last line command. Show line numbers. Hide line numbers, Search ignore case. Search case sensitive Display invisible characters (tabs) Don't display invisible characters. Show current mode of operation. Don't show current mode of operation. Clear scrambled screen.

:s/this/that Change first occurrence of this to that on current line. :s/this/that/g Change all occurrences of this to that on current line. :%s/this/that On all lines, change first occurrence of this to that. :%s/this/that/g On all lines, change all occurrences of this to that.

vi Detailed Reference

:/?
Last Line Mode
Search Functions
/exp ?exp Go forward to exp Go backward to exp

Command Mode

Input cmds

Enter Screen/Line Movement


j k h 0 $ G 3G CTRL-g CTRL-f CTRL-b

Esc
l

Input Mode
Add/Append Text
a A i 5i I Append after cursor Append at line end Insert before cursor Insert text 5 times Insert at beginning of line

Move and Insert Text


:3,8d :2,4m 9 :2,4co 9 :5,9w file Delete lines 3-8 Move lines 2-4 to 9 Copy lines 2-4 to 9 Write lines 5-9 to file

Go to line start Go to line end Go to last line in file Go to line 3 Show line number Go forward 1 screen Go backward 1 screen

Add New Lines


o O Open a line below cursor Open a line above cursor

Substitution Functions
:s/old/new Change old to new :%s/old/new/g Change all old to new

Word Movement
W 3W B 3B Go forward 1 word Go forward 3 words Go back 1 word Go back 3 words

Change Text
cw 3cw C r R Change a word Change 3 words Change line Replace one character Replace/type-over line

Save Files and Exit


:w :w newfile :w! file :q :q! :e! Write buffer to disk Write buffer to newfile Write absolutely Quit vi Quit absolutely Re-edit, discarding changes

Search Functions
n N Repeat previous search Reverse previous search

Delete Text
x dw dd D d0 dG Delete one character Delete one word Delete one line Delete to end of line Delete to beginning of line Delete to end of file

Control Edit Session


:set :set :set :set :set

nu Display line numbers nonu Don't show line numbers Cancel/Redo Functions all Show all settings u Undo last change list Display invisible chars . Do last change again showmode Display editing mode

Other Useful Features


:r file :!command :sh :| ZZ Read in file Execute shell command Exit to shell Shell cmd results to file Write and quit

Copy and Insert Text


Y 5Y p P Yank a copy of a line Yank a copy of 5 lines Put below cursor Put above cursor

Word Processing Functions


J 4J Join next line to current Join next 4 lines to current

You might also like