Vim (vi) usage tips and shortcut

Tags: , ,
Share the joy
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

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
ctrl+w

: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

Sharing is caring
Sharing is caring

About Namran Hussin

a soft spoken guy... with exceptional interest in computers and technology. I love to learn new thing and also love to break thing for the sake of learning.. but I do abide to the self-imposed limitation or certain thing such as social thing in life, thing can be done and thing that must be avoided at whatever cost such as drug,illegal tracking, smoke,illicit activity..etc.muahahaha let's share what we had in this short term of the life.! make it worth of the living.~

%d bloggers like this: