Effective Use of VIM - Part 4

Sunday, October 5, 2008

Effective Use of VIM - Part 4

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



Here is Part 4 of the series on various Tips & Tricks for using VIM Effectively...

== PART 4 ==

Search inside a File

You use / (forward slash) to search inside a file in VIM.

If incsearch is set (directly or thru .vimrc), then as soon as you type anything after the /, VIM starts searching incrementally, very useful.

You can have all the power of regular expressions in VIM search.

Example:
Suppose you need to search for all #includes, where the header file is included like #include "xyz.h", ie. using double quotes instead of angle brackets.
/#include "[a-zA-Z.]*"
- [a-zA-Z.]* means match all combinations of lowercase and uppercase a to z and a . (dot).

Go to File

CTRL + W, F – Find file at cursor in PATH, opens if found (you can also use gf to go to the file directly).

CTRL + O OR CTRL + T - take you back to where you came from.

Keyword Program

SHIFT + k - if pressed within a word, it will execute a command (which can be specified), and passes the word as argument. Default is man. So, if you press SHIFT + k on a function, it will directly go to its man page, very useful during programming.

Indent

= (equal sign)

Indents text, according to the programming language.

= can be used with any of the locators.

=% - indent upto the matching closing paranthesis / brace.
=5 - indent 5 lines

More Settings...

ai - Auto indent
nows - No wrap scan (when search reaches one end, it won't wrap)
noflash - No flash
tabstop - Tab width (how much a tab moves)
shiftwidth - Shift width (how many spaces to be shifted when using =)
expandtab - Expand tab (when tab is pressed, it is automatically replaced by that number of spaces)
hlsearch - Highlight search
incsearch - Incremental search

To be continued...

Like it? Subscribe via RSS


You may have found out unique ways of doing things in VIM, pls share...

See also... » Mind Quiz 4

» Help and Support Thread

» Linux Commands I Hardly Knew - Reloaded

» Linux Commands I Hardly Knew

» Unlock a PC on Windiows XP ???


ATOzTOA : Latest Headlines


0 comments:

Post a Comment