Quick vi Commands


Cheat sheet for vi

To Start

vi filename

To exit

:wq or 😡 Write and exit file

:q! Exit and don’t save changes

:q                            Exit file

:w                           Save file

Inserting / Adding text

i                insert text before cursor, until <Esc> hit

I              insert text at beginning of current line, until <Esc> hit

a              append text after cursor, until <Esc> hit

A            append text to end of current line, until <Esc> hit

o             open and put text in a new line below current line, until <Esc> hit

O             open and put text in a new line above current line, until <Esc> hit

Delete / Copy / Paste

D delete the remainder of the line, starting with current cursor position

dd delete entire current line

yy            copy  the current line

Nyy       copy the next N lines, including the current line

p            paste the line(s)

Search Text

/string    search forward for occurrence of string in text

?string                 search backward for occurrence of string in text

n           move to next occurrence of search string

N           move to next occurrence of search string in opposite direction

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s