The best possible resource on vim is the book Practical Vim. I’ve outlined some of my personal favorites, and will also put in some plugins that might just change your world.
def (arg1, arg2, arg3), where your cursor is somewhere in the middle of the parenthesis.
di(deletes everything between the parenthesis. That says “change everything inside the nearest parenthesis”. Without text objects, you would need to do
%- jumps between matching
ctrl+o- go backwards in the jump list
ctrl+i- go forwards in the jump list
g;- go backwards in the change list
g,- go forwards in the change list
Ctrl+r + 0in insert mode inserts the last yanked text (or in command mode)
gv- reselect (select last selected block of text, from visual mode)
The most helpful part of plugins is that they make vim a better fully featured IDE. Concepts like global search and finding a file to open are solved with plugins. They also can bring out some missing features of vim, like automatic commenting.
##Regex and Searching
\in your search term. If you just want “regex on” or “regex off” then always search in Very Magic or Very No Magic mode.
Start a search with
\v. Everything else can act like a normal regex search, except you have to escape
\. If you are searching backwards, you’ll also have to escape
wwwand ending with
> characters are special for start and end of word. Escape them to search for them literally.
###Literal Search (Very No Magic Mode)
Start a search with
\V. Now you only have to escape
\. It would be nice if you didn’t have to escape anything, but alas vim is not like this.
###Advanced: Match a subsection of your search Let’s say you have this file
www.yahoo.com blah some other stuff www.google.com www.ebay.org
And you want to change it to
www.chase.com blah some other stuff www.chase.com www.chase.org
What you’re doing is saying find all domain names and change the inner part to
chase. You can do this by specifying the part of the search to match.
\zs before where you want to match and
\ze after where you want to match.
So in this case:
i. We could then use this search:
\v\W\zsi\ze\W. Note: Use
\Wmatches everything except
*in normal mode, while having your cursor over the word you want to search.
gnmeans “select the next search term”.