Skip to content

fszostak/vi-manual

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 

Repository files navigation

VI Editor Manual

Initial version 2004 by Fabio Szostak, updated 2018

VI editor command summary. Enjoy and increase it. You're welcome.


Open, save and exit

On shell:

$ vi filename

On editor:

:e filename open file
:e! filename open file with ignore changes
:e# or :e!# open previous file
:wq or :x or :x! save and exit
:q! exit without save

!!command run command and get output

Check on bottom of screen the current mode:

nothing is on command mode
-- INSERT -- is on insert mode
-- REPLACE -- is on replace mode

Note: Always type esc to switch to command mode

Basic commands

Navigation

h go left, like
j go down, like
k go up, like
l go right, like
0 begin of line
$ end of line
H top of screen
L bottom of screen
w begin next word
e end next word
b back previous word
CTRL-F go next page, like PageDown
CTRL-B go previous page, like PageUp
G go end of file
:n go to line number
:$ go to end of file

Search

/ + str find next match str
? + str find previous match str
% find match close char {}()[]

Insert mode

i enter on insert mode
I at begin of line
a at next character
A at end of file
o at next line
O at previous line

Undo changes

u last command
U all commands in current line

Delete

x delete current character
dd delete current line
:g/regexp/d delete all lines match regexp

Replace mode

r replace one character
R enter in replace mode
cw replace current word
s replace one char and enter in replace mode

:x,y s /find/replace/g find and replace
x,y is line range, % is oll, g is all occurences in line

~ change character case (uppercase|lowercase)

Join lines

J Join current line with next line

Repeat

. Repeat last command

Indent

>> shift current line to right
<< shift current line to left

Put to buffer

yy or Y put current line to temporary buffer

Paste buffer

P paste buffer previous line
p paste buffer next line

Mark

m[a-z] put [a-z] mark in current line
[a-z] go to [a-z] mark
’’ go to last mark

Advanced commands

Navigation

n h go n chars to left
n j go n lines to down
n k go n lines to up
n l go n chars to right

n w go next n words
n e go next n words at end
n b go back n words

n G go n lines from begin of file

Insert mode

n i insert n times after esc
n I insert n times after esc
n a insert n times after esc
n A insert n times after esc

Delete

n x delete n characters
n dd delete n lines
d/ str delete until match str
d% delete match character {}
dG delete until end of file
d1G delete to beginning of file
d n G delete to beginning of file, except n first lines
dw delete to end of word
d n w delete n words

Replace mode

n s replace n characters
c n w replace n words
c$ replace to end of line
c0 replace to beginning of line
c/ str replace until match str
c% replace to match char {}
cG replace to end of file

Join lines

nJ n join *n lines above current line

Indent

n >> shift n lines to right
n << shift n lines to left
>% shift until match char to right
<% shift until match char to left
>G shift to end of file
>1G shift to beginning of file
>/ str shift until match str

Registers

[a-z] open the register
@ [a-z] execute commands into the register

Put to register

r yy put current line to register “r”
r y’ m put until match mark "m” to register "r"
r y/ str put until find string "str" to register "r"
r y$ put until find end of line to register "r"
r yw put one word to register “r”

Get from register

r p paste content of register “r” after
r P paste content of register “r” before

RegExp Replace Example

 ORIGINAL FILE         CHANGED FILE
 ........ 1234.10  =>  ........ 1234,10
 ........ 2233.20  =>  ........ 2233,20 

Command:       :1,$ s /\.\([0-9]\)/,\1/

Find:     .(dígit 0 to 9)
Replace:  ,(dígit 0 to 9)

About

VI Manual by fszostak march2004

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published