Using vi in Linux


Singles:  (Command executes immediately)
insert, append, replace, open new line, paste, yank one line,
delete to end of line, join 2 lines, delete chars, undelete, substitute, swap between upper and lower case

Movement:  (Command executes immediately)
number<ENTER-KEY> (jump that many lines down)

yy          (yank/copy 1 line)
dd          (del 1 line)
5yy   p     (copy and paste)
7dd   p     (cut and paste)
/searchstring    (search for something - use n and N to search again down or up)

Commands that need qualifiers:

Colon Commands:
:w newfilename    (save under a new filename - next save reverts back to old filename)

:r filename.txt   ( read this file into where the cursor currently is)
:r!ls             ( run this command and drop the results right here)
:r ! pwd
:r!ls | grep thisfile (running a command, using a pipe
                       and dropping the rsults right here.)
:num              (tell me current line number)
:set nu           (turn on line numbers)
:split            (split the screen - :q to get out of a split)
:split filename   (split the screen between current file and filename)

CTRL+t            (if in insert mode then insert a tab)

Visual Mode (probably need to have vim installed)
v         (start selecting from the current cursor position,
           press an action key (such as y to yank or d to delete)
           to stop selecting)
V         (same as above, except line by line)
CTRL+v    (same as above, except select by block mode)

If you give 2 or more filenames on the command line then use
:next and :prev to switch between them.  For Example:
vi file1 file2

The power of vi - wow this is cool stuff:

Highlight some lines with visual (capital v), then run a command on it with :,
run the command !sort or !uniq, etc...:


Extend your vi here, check out “map” in the .exrc file:

Try to stay out of caps lock.
When not inserting data remain in vi “command mode”.
These 2 tips will help you navigate vi much easier.

prev next index

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Exit mobile version