Vi editor Cheat Sheet - Admin's Choice

[Pages:2]vi editor Cheat Sheet

File Open

Saving and Quitting

Moving Cursor in file

Open or create

Save changes (write h

Move one character left

vi filename

file

:w

buffer)

j

Move one line down

vi

Open new file to

Write buffer to

be named later :w filename named file

k

Move one line up

Recover crashed

vi -r filename file

:wq

Save changes and quit vi

l

Move one character to right

Open file read-

view filename only

ZZ

Save changes and w quit vi

Move one word right Move one word (past

Insert Characters and Lines

Quit without saving W

punctuation) right

Insert

:q!

changes

b

Move one word left

characters right of

a

cursor

Text Change Operations

Move one word (past

B

punctuation) left

Insert characters end cc

A

of line

Change line

Change characters

e

Move to of current word end

Insert characters left

in a word or entire

i

of cursor

cw

word right of cursor Moving Cursor with keys

Insert

characters beginning

I

of line

C

Insert line below

o

cursor

s

Insert line above

O

cursor

Delete Text in file

r

Delete character at r Return

x

the cursor

Delete character to J

the left of the

X

cursor

Delete word (or part

of word to right of xp

dw

cursor)

Delete current

dd

line

Delete part of line

~

Change from cursor cursor to end of line

Substitute string for character(s) from cursor forward

Replace character with other character at cursor

Break line at cursor

Join to current line line below

Transpose character cursor and character to right

Change case of letter to uppercase or lowercase at cursor

Return/Enter Move down one

key

line down

Backspace

Move left one character left

Spacebar

Move right one character right

Moving on Screen

H

Move to of screen top

Move to middle of

M

screen

Move to bottom of

L

screen

Moving on Screen using ctrl key combination

Ctrl-f

Page forward one screen forward

Ctrl-d

Scroll forward onehalf screen

D

to right of cursor

Delete to end of

u

Undo previous command

Ctrl-b

Page backward one screen

dG

file

Delete - beginning

U

Undo all changes to current line

Ctrl-u

Scroll backward one-half screen

d1G

of file to cursor

Undo previous

:1,4 d

Delete lines 1 to 4

:u

line command

Copy and Move lines

Yank or

yy

copy current line

4yy

Copy 4 lines

Y

Yank or copy line

Put yanked or

deleted line below

p

current line

Put yanked or

deleted line above

P

current line

Copy lines 1-2 :1,2 co 3 and put after line 3

Move lines 4-6 and :4,6 m 7 put after line 7

Inserting a File Into a File

set/ignore case for search

:r filename

Insert (read) file

after cursor

:set ic

Searches should ignore case

Insert file after :34 r filename line 34

Searches should be :set noic case sensitive

Show/hide Line Numbers

Clearing the Screen

:set Show line nu numbers for all lines

Clear screen of stdCtrl-L io messages

:set nonu

Hide numbers for all line Executing Shell Command

go to line

G

Go to last line of file

Execute command -

:!cmd cmd

1G

Go to first line of file

21G

Go to line 21

Search and Replace

/string ?string

Search for string anywhere in file Search backward for string

n

Find next occurrence of string in search direction

N

Find previous occurrence of string in search direction

:%s/search/s/replace/g Search and replace in file

Visit for more Linux and Unix Articles and References at:



................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download