How to use basic VI commands

I’m bored right now so I’m messing around on my server. Sometimes people forget VI Commands so I thought I’d share some basic VI commands. Hopefully this quick reference can help somebody out. For those that don’t know, VI is an editor used in the Linux/Unix environment to edit files that contain text.

To edit a file in SSH you’ll run this command

vi /path/to/file/

First… you must learn there are 2 different modes.

Insert mode and Command mode

hit escape to enter command mode.
from command mode… these are the keys to go into insert mode

i => will make you start inputing at the cursor
a => will make you start inputing after the cursor
o => will open up a new line below the current line your cursor is on,and move the cursor there.

when in insert mode, hit the escape key to enter command mode again
basic command mode commands

:w => save the file
:wq => save the file and quit
:q! => quit w/o saving

/textstring => searches for the textstring in the file ( hit n to find
next instance and N to find previous )

simple copy and paste

yy => yanks single line ( aka copy line into buffer)
p => will paste buffer onto the line below where the cursor is.

to get fancy, you can prepend yy with the number of lines you want to
copy ex .

5yy  => will yank 5 lines from where the cursor is and below in the buffer
p => will paste those 5 lines

dd => cuts single line ( aka cuts line into buffer )
p => will paste cut buffer onto the line below where the cursor is.

And that’s about it. For more in depth instructions you can check out these two sites:

Leave a Reply

Your email address will not be published. Required fields are marked *