Vim (vi) usage tips and shortcut

Ok. I had been introduced to “Vim” (vi) quite few years ago… i think was 2005?
Before that I was using “pico” which is meant for pine or reading email client if not mistaken.
At that time , i was hardly know how to use vi .
remembering how did i always messed up whenever tried to edit cronjob using
“crontab -e” . it spawn the default editor instead of pico.
most of the system i used by then was vi..

First few attempt was the following sequence :

vi  file.txt
:q! - quit without change
i - insert 
:w - write to file
:wq - write to file and quit
:wq! - write and quite with override option..
doesn't care if file is not written due to permission or  anything.
 (that time got no sense of file permission yet.. haha)

then ..

vim -r file.txt - recover from a .swp file?
view file.txt - just view the file without altering it.. 
as someone else is also accessing the file.
y - for yank
d - delete
p - for paste.
3yy - for three line copy 
r - for replace
v - for visual mode.
i - for insert mode.

then ..

:%s/texttomatch/replacewiththis/g  - for replacing thing
gg - go to top most of current file
G - go to most bottom?

then few week back.. learnt the following..

:split .  - split the screen horizontally with the current folder content.. which is clickable.

to move between the splitted window

:vsplit . - split the screen vertically .. with current folder.

shift+v – to start line selection. (change to visual mode)

then followed by down arrow to highlight the line.
press y to yank..highligted line.
then move the cursor to where to put..
press p to paste..

% - to find the next closing bracket.
u - to undo
ctrl+r - to redo
:set ai -  turn on auto-indent
:set noai  - turn off auto-indent .. useful whenever pasted from other window.

and also the ~/.exrc with the following content.

set ts=2
set shiftwidth=2
set ai
set background=dark

I believe there are many more usage…
let’s collect it before I forgot how to use them

Related Post

3 Responses

  1. Girish says:

    This is a great article. I was able to setup a monitoring service quickly. I have visited a lot of websites and none of them got me to a place where I could monitor my servers this quickly.


  2. namran says:

    to use snmp to monitor other thing..

    better to get the utils correct with this.

    yum install net-snmp-utils

    and then can test with ..

    snmpwalk -v 1 localhost -c public system

  3. looker says:

    Looking forward start investing very soonBeautiful! Great site!


Leave a Reply

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