
This is a Basic vi Cheat Sheet. Influenza A virus subtype H5N1 modest lead to help readers role vi editor to a greater extent than efficiently.
This part contains the unproblematic vi commands.
vi is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behaviour of vi as well as programs based on it, as well as the ex editor linguistic communication supported inside these programs, is described past times (and so standardized by) the Single Unix Specification as well as POSIX.
vi Cheat Sheet – Basic
Modes
Vi has 2 modes insertion means as well as dominance mode. The editor begins inwards dominance mode, where the cursor motion as well as text deletion as well as pasting occur. Insertion means begins upon entering an insertion or alter command. [ESC] returns the editor to dominance means (where yous tin quit, for representative past times typing :q!). Most commands execute every bit shortly every bit yous type them except for “colon” commands which execute when yous press the provide key.
Quitting
: x |
Exit, saving changes |
:q |
Exit every bit long every bit at that spot accept been no changes |
ZZ |
Exit as well as salve changes if whatever accept been made |
:q! |
Exit as well as ignore whatever changes |
Inserting Text
i |
Insert earlier cursor |
I |
Insert earlier line |
a |
Append afterwards cursor |
A |
Append afterwards line |
o |
Open a novel business afterwards electrical current line |
O |
Open a novel business earlier electrical current line |
r |
Replace i character |
R |
Replace many characters |
Motion
h |
Move left |
j |
Move down |
k |
Move up |
l |
Move right |
w |
Move to adjacent word |
W |
Move to adjacent blank delimited word |
b |
Move to the get-go of the word |
B |
Move to the get-go of blank delimited word |
e |
Move to the terminate of the word |
E |
Move to the terminate of Blank delimited word |
( |
Move a judgement back |
) |
Move a judgement forward |
{ |
Move a paragraph back |
} |
Move a paragraph forward |
0 |
Move to the get-go of the line |
$ |
Move to the terminate of the line |
1G |
Move to the foremost business of the file |
G |
Move to the concluding business of the file |
nG |
Move to nth business of the file |
:n |
Move to nth business of the file |
fc |
Move forrad to c |
Fc |
Move dorsum to c |
H |
Move to exceed of screen |
M |
Move to pump of screen |
L |
Move to bottom of screen |
% |
Move to associated ( ), { }, [ ] |
Deleting Text
Almost all deletion commands are performed past times typing d followed past times a motion. For example, dw deletes a word. Influenza A virus subtype H5N1 few other deletes are: |
x |
Delete grapheme to the correct of cursor |
X |
Delete grapheme to the left of cursor |
D |
Delete to the terminate of the line |
dd |
Delete electrical current line |
:d |
Delete electrical current line |
Yanking Text
Like deletion, near all yank commands are performed past times typing y followed past times a motion. For example, y$ yanks to the terminate of the line. Two other yank commands are: |
yy |
Yank the electrical current line |
:y |
Yank the electrical current line |
Changing text
The alter dominance is a deletion dominance that leaves the editor inwards insert mode. It is performed past times typing c followed past times a motion. For representative cw changes a word. Influenza A virus subtype H5N1 few other alter commands are: |
C |
Change to the terminate of the line |
cc |
Change the whole line |
Putting text
p |
Put afterwards the seat or afterwards the line |
P |
Put earlier the seat or earlier the line |
Buffers
Named buffers may endure specified earlier whatever deletion, change, yank or seat command. The full general prefix has the shape “c where c is whatever lowercase character. for example, “adw deletes a discussion into buffer a. It may thereafter endure seat dorsum into text amongst an appropriate “ap. |
Markers
Named markers may endure onslaught whatever business inwards a file. Any lower instance alphabetic quality may endure a marking name. Markers may likewise endure used every bit limits for ranges. |
mc |
Set marking c on this line |
`c |
Go to get-go of marking c line. |
‘c |
Go to foremost non-blank grapheme of marking c line. |
Search for strings
/string |
Search forrad for string |
?string |
Search dorsum for string |
n |
Search for adjacent instance of string |
N |
Search for previous instance of string |
Replace
The search as well as supervene upon business office is accomplished amongst the :s command. It is commonly used inwards combination amongst ranges or the :g dominance (below). |
:s/pattern/string/flags |
Replace pattern amongst string according to flags. |
g |
Flag – Replace all occurrences of pattern |
c |
Flag – Confirm replaces. |
& |
Repeat concluding :s command |
Regular Expressions
. (dot) |
Any unmarried grapheme except newline |
* |
zero or to a greater extent than occurrences of whatever character |
[…] |
Any unmarried grapheme specified inwards the set |
[^…] |
Any unmarried grapheme non specified inwards the set |
^ |
Anchor – get-go of the line |
$ |
Anchor – terminate of line |
\< |
Anchor – get-go of word |
\> |
Anchor – terminate of word |
\(…\) |
Grouping – commonly used to grouping conditions |
\n |
Contents of nth grouping |
[…] – Set Examples
[A-Z] |
The SET from Capital Influenza A virus subtype H5N1 to Capital Z |
[a-z] |
The SET from lowercase a to lowercase z |
[0-9] |
The SET from 0 to ix (All numerals) |
[./=+] |
The SET containing . (dot), / (slash), =, as well as + |
[-A-F] |
The SET from Capital Influenza A virus subtype H5N1 to Capital F as well as the dash (dashes must endure specified first) |
[0-9 A-Z] |
The SET containing all uppercase letters as well as digits as well as a space |
[A-Z][a-zA-Z] |
In the foremost position, the SET from Capital Influenza A virus subtype H5N1 to Capital Z
In the minute grapheme position, the SET containing all letters |
Regular Expression Examples
/Hello/ |
Matches if the business contains the value Hello |
/^TEST$/ |
Matches if the business contains TEST past times itself |
/^[a-zA-Z]/ |
Matches if the business starts amongst whatever letter |
/^[a-z].*/ |
Matches if the foremost grapheme of the business is a-z as well as at that spot is at to the lowest degree i to a greater extent than of whatever grapheme next it |
/2134$/ |
Matches if business ends amongst 2134 |
/\(21|35\)/ |
Matches is the business contains 21 or 35
Note the role of ( ) amongst the pipage symbol to specify the ‘or’ condition |
/[0-9]*/ |
Matches if at that spot are null or to a greater extent than numbers inwards the line |
/^[^#]/ |
Matches if the foremost grapheme is non a # inwards the line |
Notes:
1. Regular expressions are instance sensitive
2. Regular expressions are to endure used where pattern is specified |
Counts
Nearly every dominance may endure preceded past times a publish that specifies how many times it is to endure performed. For example, 5dw volition delete five words as well as 3fe volition displace the cursor forrad to the tertiary occurrence of the alphabetic quality e. Even insertions may endure repeated conveniently amongst this method, enjoin to insert the same business 100 times. |
Ranges
Ranges may precede most “colon” commands as well as motion them to endure executed on a business or lines. For representative :3,7d would delete lines 3-7. Ranges are commonly combined amongst the :s dominance to perform a replacement on several lines, every bit amongst :.,$s/pattern/string/g to brand a replacement from the electrical current business to the terminate of the file. |
:n,m |
Range – Lines n-m |
:. |
Range – Current line |
:$ |
Range – Last line |
:’c |
Range – Marker c |
:% |
Range – All lines inwards file |
:g/pattern/ |
Range – All lines that incorporate pattern |
Files
:w file |
Write to file |
:r file |
Read file inwards afterwards line |
:n |
Go to adjacent file |
:p |
Go to previous file |
:e file |
Edit file |
!!program |
Replace business amongst output from program |
Other
|
Toggle upwards as well as lower case |
J |
Join lines |
. |
Repeat concluding text-changing command |
u |
Undo concluding change |
U |
Undo all changes to line |
vi Cheat Sheet – printable – blackMORE Ops
Download as well as impress vi cheat canvas image. Stick it adjacent to your desk as well as you’ll ever accept a quick lead to hold back at. Click on the icon to larn the total version.

End of vi Cheat Sheet – Basic.
Thanks for reading.
Buat lebih berguna, kongsi: