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!

Monday, November 30, 2009

Text States

If you're using Vim 7+, you can use g- and g+ to go between text states. For a more advanced usage see the :help earlier and :help later.

Tuesday, November 24, 2009

Jumping to a Buffer

If you have split windows open with multiple buffers, you can jump directly to a specific buffer number by doing the following:

N<C-w><C-w>

N is the window number you want to move the cursor to.

Thanks to Duff for the coffee!

Monday, November 23, 2009

Indent From Insert

In the comments of my last post, graywh left a great tip that I didn't know about. If you're working in insert mode, you can change the indent level of the current line using <C-t> and <C-d>. These commands work no matter where your cursor is positioned on the current line and adjust the indent level based on your shiftwidth setting.