Using vi in Linux
 

Using vi in Linux

 

This post was last updated on May 27th, 2020 at 05:36 pm

vi

Singles:  (Command executes immediately)
iIaArRoOpPY
DJxXu(U)sS~
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)
up/down/left/right
kjhl
CTRL+U CTRL+D wWeEbB
number<ENTER-KEY> (jump that many lines down)

Combo's:
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:
dc

Colon Commands:
:w
:q
:w!
:q!
:wq
: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 ! 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
:next
:prev


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...:

:'<,'>!sort
:'<,'>!uniq

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

http://grox.net/doc/unix/exrc.php

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

Previous Setting Routes in Linux
Next Using find in Linux
 

About author

shibaa987
shibaa987 268 posts

Linux kernel developer and a firmware developer with an experience of 10+ years.

View all posts by this author →

You might also like

VIM tips 0 Comments

[VIM] Removing new line at the End Of File in VIM

This post was last updated on June 23rd, 2020 at 07:57 pmVim is the best text editor when it comes to speed, handy and features comparison with any other text

VIM tips 0 Comments

How to fix E575: viminfo: Illegal starting char in line

This post was last updated on November 3rd, 2020 at 05:23 pmOnce I was working with the VIM editor and everything was normal. When I started using the same VIM

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply