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

vi-quick-ref linux embeded

This document is a quick reference guide for using the vi text editor, detailing commands for entering and leaving vi, file manipulation, and various editing operations. It includes instructions for undoing changes, navigating within files, and manipulating text, as well as options for customizing vi's behavior. The guide serves as a comprehensive overview for users to efficiently utilize vi's features and commands.

Uploaded by

younessov
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)
12 views2 pages

vi-quick-ref linux embeded

This document is a quick reference guide for using the vi text editor, detailing commands for entering and leaving vi, file manipulation, and various editing operations. It includes instructions for undoing changes, navigating within files, and manipulating text, as well as options for customizing vi's behavior. The guide serves as a comprehensive overview for users to efficiently utilize vi's features and commands.

Uploaded by

younessov
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 Quick Reference

Entering/leaving vi Undo, redo, retrieve


% vi name edit name at top u undo last change
% vi +n name ... at line n U restore current line
% vi + name ... at end . repeat last change
% vi −r list saved files "d p retrieve d’th last delete
% vi −r name recover file name
% vi name1 name2 ... edit first; rest via :n Counts before vi commands
% view name read only mode
Typing a number before a vi command will tell vi to "repeat"
the command that many times. More specifically:
Vi states
line/column number z G |
Command Normal and initial state. Others return scroll amount ˆD ˆU
here. ESC (escape) cancels partial replicate insert a i A I
command. repeat effect most rest
Insert Entered by a i A I o O c C s S R.
Enter your arbitrary text then ter-
Operators (double to affect lines)
minates with ESC character.
These operators act like a prefix, you type the operator ("d"
for example) then type a cursor movement command to
The display
specify what the operator will affect (example: "dw" deletes a
Last line Error messages, echoing input to : / ? word)
and !, feedback about i/o and large
d delete
changes.
c change
@ lines On screen only, not in file.
y yank lines to buffer
˜ lines Lines past end of file.
< left shift
ˆx Control characters, ˆ? is delete.
> right shift
! filter through UNIX command
File manipulation
:w write out changes Simple commands
:wq write and quit vi dw delete a word
ZZ exit from vi, saving changes de ... leaving punctuation
:w name write file name dd delete a line
:w! name overwrite file name 3dd ... 3 lines
:q quit i abc ESC insert text abc
:q! quit, discard ALL changes cw new ESC change current word to new
:e name edit file name xp transpose characters
:e! reedit, discard changes
:e # edit alternate file
Character positioning
:n edit next file in arglist
:sh run shell, type exit to return ˆ first non blank
:!cmd run cmd, then return 0 beginning of line
ˆG shows current filename and line $ end of line
h or → forward
l or ← backwards
Insert and replace
ˆH same as ←
a append after cursor space same as →
A append at end of line fx find character x forward
i insert before Fx ... backwards
I insert before first non-space tx up to character x forward
o open line below Tx ... backwards
O open above ; repeat last f F t or T
rx replace single char with x , opposite direction of ;
R replace multiple characters | to specified column
10 | to 10th column
Corrections during inserting % find matching ( { ) or }
ˆH erase last character
ˆW erases last word
ˆD backtab over autoindent
ˆVˆX puts control character ˆX in text
ESC ends insertion, back to command
Vi Quick Reference
Words, sentences, paragraphs Adjusting the screen
w word forward ˆL clear and redraw messy screen
W ... ignore punctuation ˆR retype, eliminate @ lines
b word backwards zCR redraw, current at window top
B ... ignore punctuation z− ... at bottom
e end of word z. ... at center
E ... ignore punctuation zn . use n line window
) sentence forward
( sentence backwards Miscellaneous operations
} paragraph forward
C change rest of line
{ paragraph backward
D delete rest of line
Y yank lines
Line positioning s substitute chars
H home window line J join lines
L last window line x delete characters
M middle window line X ... before cursor
+ next line, at first non-white
− previous line, at first non-white Yank and put
↓ or j next line, same column
p put back lines
↑ or k previous line, same column
P put before
"xy yank (copy) to buffer x
Marking and returning "xd delete into buffer x
`` previous place in file "xp put from buffer x
´´ ... at first non-blank in line NOTE: the yank and delete commands above are followed by
mx mark position with letter x a cursor movement command to specify what will be yanked
`x to mark x or deleted. (see Operators section)
´x ... at first non-blank in line
Initializing VI options
Scanning pattern formation
set option enable option
/pattern next line matching "pattern" set nooption disable option
?pattern ... find backwards set option=value give value val
ˆ beginning of line set all show all options
$ end of line set show changed options
. any character
* any number of preceding
Useful options
.* matches anything or nothing
\< beginning of word autoindent ai supply indent
\> end of word autowrite aw write before changing files
[abc] a single char (a or b or c) ignorecase ic in scanning
[ˆabc] ... any char except a or b or c lisp ( ) { } are s-exp’s
[x−y] ... between x and y list print ˆI for tab, $ at end
magic . [ * special in patterns
number nu number lines
Positioning within file
paragraphs para macro names which start ...
ˆF forward one screenfull redraw simulate smart terminal
ˆB backward one screenfull scroll command mode lines
ˆD scroll down half screen sections sect macro names ...
ˆU scroll up half screen shiftwidth sw for < >, and input ˆD
ˆE scroll window down 1 line showmatch sm to ) and } as typed
ˆY scroll window up 1 line window visual mode lines
G goto line (end default) wrapscan ws around end of buffer?
10G goto 10th line in file wrapmargin wm automatic line splitting
/pattern next line matching pattern
?pattern prev line matching pattern
n repeat last / or ?
N reverse last / or ?
% find matching ( ) { or }
]] next section/function
[[ previous section/function

You might also like