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

Sibananda Sahu
Sibananda Sahu 138 posts

A Linux Kernel Developer and a Firmware Developer by profession. Have worked with few big companies: BROADCOM Corporation, Cypress Semiconductor, LSI Corporation, TOSHIBA Corporation, Western Digital; on various cutting edge technologies and product lines, such as: RAID storage Driver, SSD Firmware, WLAN Firmware etc. Having more than 9 years of experience in Software Engineering domain. Now, took a pledge to educate all aspirant students to teach about Linux Kernel Development.

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

Once I was working with the VIM editor and everything was normal. When I started using the same VIM editor on the other day and tried to open any file,

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply