Docsity

vi Editor Commands Cheat Sheet, Cheat Sheet of Electromechanical Systems

Toggle sidebar
bg1
vi editor commands
3 modes of vi
command mode
you can navigate the file and use the commands on
this sheet
insert mode
you insert text into the file and can move around
(using the arrows) in the file if you are using vim.
You exit insert mode by pressing the ESC key.
special command mode
Allows you to enter special commands. While in
command mode, press :
enter insert mode commands
i insert before cursor
o lower-case oh opens a new line (below)
O upper-case oh opens a new line (above)
a append (insert after cursor)
A append at end of line
saving, exiting
:w write contents to disk
:wq write contents and quit
ZZ write contents and quit
:q quit
:q! quit and don’t save changes
searching
/foo search forward for “foo”
?foo search backwards for “foo”
n repeat last search
delete (and place in buffer)
x delete current character
10x delete 10 characters
dd delete current line
6dd delete 6 lines
d0 delete to beginning of line
d$ delete to end of line
dw delete word
3dw delete 3 words
copy (and place in buffer)
yy yank (copy)
5yy yank 5 lines
pasting
p lower-case pee pastes after cursor
P upper-case pee pastes before cursor
using other paste buffers
"a7dw delete 7 words and place in buffer a
"b5dd delete 5 lines and place in buffer b
"ap paste contents of buffer a
"bp paste contents of buffer b
navigation
↑ move up one line
5↑ move up 5 lines
↓ move down 1 line
6↓ move down 6 lines
1G go to line 1
15G go to line 15
G go to last line
H go to top of screen (high)
L go to bottom of screen (low)
w go to next word
7w move over 7 words
b back one word
0 go to beginning of line
$ go to end of line
special command mode
:r foo read file foo into this file after cursor
:!command execute the specified unix command
and return to vi
:r !command execute the specified unix command
and read the results into this file after
the cursor
:10,20d delete lines 10-20
:1,$s/alpha/beta/g from the first line to the last
line, change all occurrences of alpha
to beta.
:5,10> indent lines 5 through 10
:20,30< de-indent lines 10 through 20
miscellaneous editing commands
u undo
. repeat last command
J join two lines
5>> indent 5 lines 1 tab
2<< de-indent 2 lines 1 tab
>% with cursor on a brace, indent bracketed block
of lines
<% de-indent bracketed block of lines
.vimrc file
:set ai sw=4
:set number
:set expandtab
:set softtabstop=4
:set smartindent

Partial preview of the text

Download vi Editor Commands Cheat Sheet and more Cheat Sheet Electromechanical Systems in PDF only on Docsity!

vi editor commands

3 modes of vi

command mode

you can navigate the file and use the commands on this sheet

insert mode

you insert text into the file and can move around (using the arrows) in the file if you are using vim. You exit insert mode by pressing the ESC key.

special command mode

Allows you to enter special commands. While in command mode, press :

enter insert mode commands

i insert before cursor o lower-case oh opens a new line (below) O upper-case oh opens a new line (above) a append (insert after cursor) A append at end of line

saving, exiting

:w write contents to disk :wq write contents and quit ZZ write contents and quit :q quit :q! quit and don’t save changes

searching

/foo search forward for “foo” ?foo search backwards for “foo” n repeat last search

delete (and place in buffer)

x delete current character 10x delete 10 characters dd delete current line 6dd delete 6 lines d0 delete to beginning of line d$ delete to end of line dw delete word 3dw delete 3 words

copy (and place in buffer)

yy yank (copy) 5yy yank 5 lines

pasting

p lower-case pee pastes after cursor P upper-case pee pastes before cursor

using other paste buffers

"a7dw delete 7 words and place in buffer a "b5dd delete 5 lines and place in buffer b "ap paste contents of buffer a "bp paste contents of buffer b

navigation

↑ move up one line 5 ↑ move up 5 lines ↓ move down 1 line 6 ↓ move down 6 lines 1G go to line 1 15G go to line 15 G go to last line H go to top of screen (high) L go to bottom of screen (low) w go to next word 7w move over 7 words b back one word 0 go to beginning of line $ go to end of line

special command mode

:r foo read file foo into this file after cursor :! command execute the specified unix command and return to vi :r! command execute the specified unix command and read the results into this file after the cursor :10,20d delete lines 10- :1,$s/alpha/beta/g from the first line to the last line, change all occurrences of alpha to beta. :5,10> indent lines 5 through 10 :20,30< de-indent lines 10 through 20

miscellaneous editing commands

u undo

. repeat last command J join two lines 5>> indent 5 lines 1 tab 2<< de-indent 2 lines 1 tab

% with cursor on a brace, indent bracketed block of lines <% de-indent bracketed block of lines

.vimrc file

:set ai sw=

:set number

:set expandtab

:set softtabstop=

:set smartindent