Wednesday, December 9, 2009

Vimgrep Tips

I've mentioned vimgrep in a previous post, but I neglected to mention a few useful flags that can be used in conjunction with it.

If you apply the 'g' flag to your vimgrep, it will return all matches instead of just one match per line.

:vimgrep /foo/g **/*

If you apply the 'j' flag, Vim will not automatically jump to the first match.

:vimgrep /foo/j **/*

Thanks to Chanel for pointing these out.

Thursday, December 3, 2009

More on Text States

A few people have asked me for more information on text states. An anonymous reader contributed the following in the comments of my previous post on the topic.

Using g+ and g- is very different than using u and ^r.

Try following:
* Create new file
* (in normal mode) Type iOne - Esc
* Type oTwo - Esc
* Type oThree - Esc
* Type oFour - Esc
* Type oFive - Esc
* Type 2u
* Type oSix - Esc
* Type oSeven - Esc

Now you have an undo tree with 2 branches. Typing u only goes up the last branch. Using g- goes up by time - branch doesn't matter here.

Have a look in :help usr_32.txt for good explanation of using the undo tree.

Thanks to whomever contributed the tip!

Wednesday, December 2, 2009

Indent From Normal Mode

From normal mode, pressing == will indent the current line.

Tuesday, December 1, 2009

Starting on a Specific Line

An anonymous reader writes:

You can open a file on the command line and automatically put the cursor on the last line by typing:

vim + file

If you want vim to start at a specific line you can do the following instead:

vim +LINENUMBER file

Thanks for the tip!