vi editor Cheat Sheet

In our day-to-day operational work , couple off times we’ve to us vi editor commands , sometimes to create or sometimes to read the file and in that case vi editor commands are very helpful to increase our productivity , especially from database perspective many times we’ve to look into different logs to figure out the root cause of the issue like digging into alert log of the database , CRS log , CSS log , OHASD log etc. although in Exadata looking only into database logs is not enough multiple times we’ve to look into other logs too like cell logs, infiband/roce switch logs , cluster patching logs etc. and without the shortcut keys anyone of us may really struggle to look for a particular issue in those files as they’re getting update in each & every second with lots of messages and during that time the shortcuts are very helpful , Some of them are as follow .

Note à I’m dividing the command in a multiple tables for a better visibility and understanding.

KEY

PURPOSE

i

To start the file in Insert Mode

esc  +  I ( In Capital Letter)

To insert the data at the beginning of the line

esc  +   a

Appends to the right of the current character

esc + A

Appends at the end of the current line

esc  +  o

Insert new line after the current line

esc  +  O ( In Capital Letter)

Insert the new line before the current line

esc  +  GG ( 2 Times)

Go to the top of the file

esc  +  Shift + G

Go into the bottom of the file

KEY

PURPOSE

l

 Move one character right

Ctrl + D

Move down one-half page from current line

Ctrl + U

Move up one-half page from current line

Ctrl + F

Move forward one page

Ctrl + B

Move back one page

G

Jump

Number + j

Move the cursor down to the current line

h

Move one character left

j

Move one line down

k

Move one line up

Number + G

This command is very helpful when we get an error in a shell script with a line number and we want to go directly into the reported line number


KEY

PURPOSE

yy

Copy current line

number + yy

Copy mentioned number of line from current line

p

Paste the copied line

u

Undo the last command

r

Redo the last command

. ( dot)

Repeat the last command

esc + ? + text

Search the text from bottom

esc + / + text

Search the text from top

esc + / + text + n

Repeat the last search

esc + ? + text + N

Repeat the last search in reverse order

esc + %s/text_to_replace/new_text/gc

Change the text globally in a file


KEY

PURPOSE

esc + ZZ

Save the current file & quit vi

esc + :w

Save current file

esc + :q!

Really quit vi

esc + :n

Jump to the line number

:f

Report the name of the currentfile and line no.












Post a Comment

Previous Post Next Post