BTW, Vim 7.2 has been released, get it here... http://www.vim.org/download.php
The Effective Use of VIM Series...
» Effective Use of VIM - Part 1
» Effective Use of VIM - Part 2
» Effective Use of VIM - Part 3
» Effective Use of VIM - Part 4
» » Effective Use of VIM - Part 5
== PART 5 ==
More Make, Grep
We have seen how to use make, grep from inside VIM in Part 3.
Here are some more options...
:copen- Open the list of locations in a new split window. You can go to an item, by highlighting it and pressing enter. It will be opened in the main split.
CTRL + w, UP/DOWN/RIGHT/LEFTwill move focus to corresponding window.
CTRL + w, wwill move between the windows, in order.
:cclose- Close the list window.
:cc- See Current. If you go to a particular item and move around the file,
:ccwill take you back to the location of the (current) item.
:cl- See List. Show a list of the items, which can be used to go to an item using
:cn[number]which is relative, just a quick calculation will do.
Basic Usage of VIM
Most us haven't ever seen this help...
usage: vim [arguments] [file ..] edit specified file(s)
or: vim [arguments] - read text from stdin
or: vim [arguments] -t tag edit file where tag is defined
or: vim [arguments] -q [errorfile] edit file with first error
Reading from stdin - this one is very useful. You can just type whatever you want. You can stop reading from stdin by
CTRL + d.
These are various keys used to jump around inside VIM...
I thought the keys on the keyboard will be of interest to you.
``(2 Acutes) - jumps between start and current cursor location.
(- jumps to start of file.
)- jumps to end of file.
`.(Acute and Dot) - moves the cursor to the line and column where the last edit was made.
'.- moves the cursor to the line where the last edit was made.
'"- moves the cursor to the last position of the cursor when you exited the previous session.
:jumps- shows the jumplist. List of files modified in order.
CTRL + o- moves the cursor to the last jump.
CTRL + i- moves the cursor to the previous jump.
H- moves the cursor to the top of the screen or viewport (viewport means what all you see in a screen at a time).
M- moves the cursor to the middle of the screen or viewport.
L- moves the cursor to the bottom of the screen or viewport.
Mark is another way of jumping around in VIM. Like bookmarks inside HTML pages.
We need to set marks for important locations in the file. After that we can jump to that locations much easily.
mx- tells Vim to add a mark called x. x can be any character.
`x(Acute and x) - tells Vim to return to the line and column for mark x.
'x- tells Vim to return to the beginning of the line where mark x is set.
:marks- shows all marks set.
:marks x- shows the mark named x.
Working with Multiple Files again?
You already know how to open multiple files in buffers from Part 2.
Here is more on multiple files...
vim -o [filelist]- Will open the files in multiple horizontal splits.
vim -O [filelist]- Same as above, but use vertical splits.
vim -p [filelist]- Opens the files in multiple tabs.
:tabe [filename]- opens the file in a new tab.
:tabnext/tabprev/tablast/tabfirst- moves around multiple tabs.
For effective use of tabs: check this.
:wa- Save all open files.
:qa- Quit all the open files in the VIM.
You can browse through the filesystem from within VIM.
vim [dir]- will open the filelist inside VIM.
Then we can use following keys for particular operations.
ENTER- open the file at cursor / go to subdir.
D- delete file at cursor.
R- rename file at cursor.
x- execute file at cursor.
-- go to previous directory.
Block Select Mode
One really great thing I liked about MS Word is its block select mode. When we drag while pressing ALT, it will select all text inside that rectangle. Very handy tool.
We have block select mode in VIM too...
CTRL + v- start Block Select Mode. Selection rectangle is drawn using UP, DOWN, RIGHT, LEFT.
You will have a pivot point around which the rectangle can be moved.
d + UP- delete current line and previous line
d + DOWN– delete current line and next line
y + UP– yank current line and previous line
y + DOWN– yank current line and next line
:CTRL + f- will open the history of VIM commands in a split. Can execute by highlighting and pressing ENTER.
P- paste above / left of the cursor.
p- paste below / right of the cursor.
D- deletes till the end of the line.
d$also does the same.
:shell- Open a shell. Returns to VIM once you close the shell.
Start typing a VIM command after
UPwill match it with previous commands starting with that string.
.(Dot) - will perform the previous action like d, y etc. If you used
5ddfor deleting five lines. Pressing
.will do that action again and delete 5 more lines.
When using search and replace...
We can replace a particular string pattern with another using
[location]- where to search.
10,20will search from line 10 to 20.
%will search whole file.
[source] is replaced by
g- replaces globally
c- asks for confirmation
[destination]can have control characters for special purposes. One particular is
&anywhere in the
[destination]will be replaced by
:%s/hello/& world/g- will replace 'hello' with 'hello world'
Like it? Subscribe via RSS
You may have found out unique ways of doing things in VIM, pls share...