0% found this document useful (0 votes)
6 views2 pages

VI Reference

vi commands

Uploaded by

sharmir08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

VI Reference

vi commands

Uploaded by

sharmir08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

vi editor basics

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

/string Search forward for string


?string Search backward for string
n Find next occurrence of string
N Find previous occurrence of string
: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
Input cmds
::/ ? Command
Last Line Mode Input
<Return> <Esc>
Mode Mode

Search Functions Screen/Line Movement Add/Append Text


/exp Go forward to exp j ↓ k↑ h← l→
?exp Go backward to exp a Append after cursor
0 Go to line start A Append at line end
$ Go to line end i Insert before cursor
Move and Insert Text G Go to last line in file 5i Insert text 5 times
:3,8d Delete lines 3-8 3G Go to line 3 I Insert at beginning of line
:2,4m 9 Move lines 2-4 to 9 CTRL-g Show line number
:2,4co 9 Copy lines 2-4 to 9 CTRL-f Go forward 1 screen Add New Lines
:5,9w file Write lines 5-9 to file CTRL-b Go backward 1 screen
o Open a line below cursor
Word Movement O Open a line above cursor
Substitution Functions
W Go forward 1 word
:s/old/new Change old to new
3W Go forward 3 words Change Text
:%s/old/new/g Change all old to B Go back 1 word
new 3B Go back 3 words cw Change a word
3cw Change 3 words
Save Files and Exit Search Functions C Change line
:w Write buffer to disk n Repeat previous search r Replace one character
:w newfile Write buffer to newfile N Reverse previous search R Replace/type-over line
:w! file Write absolutely
:q Quit vi Delete Text
x Delete one character
:q! Quit absolutely
dw Delete one word
:e! Re-edit, discarding dd Delete one line
changes D Delete to end of line
d0 Delete to beginning of line
Control Edit Session dG Delete to end of file
:set nu Display line numbers
:set nonu Don't show line numbers
Cancel/Redo Functions
:set all Show all settings
u Undo last change
:set list Display invisible chars
. Do last change again
:set showmode Display editing mode
Copy and Insert Text
Other Useful Features Y Yank a copy of a line
:r file Read in file
5Y Yank a copy of 5 lines
:!command Execute shell command
p Put below cursor
:sh Exit to shell
P Put above cursor
:| Shell cmd results to file
ZZ Write and quit
Word Processing Functions
J Join next line to current
4J Join next 4 lines to current

You might also like