Vim Tips

Pull the Word under the Cursor into a Command Line

I'm always forgetting this one...

use CTRL-R CTRL-W to pull the word under the cursor into the Vim command line, useful for searching etc.

Open a file with the cursor positioned on a specific line

This is a really handy tip for those occasions when you want to make a quick edit and you know the line number you're interested in:

matason$ vim +92 sites/default/settings.php

...will open settings.php with the cursor positioned at line 92

It also works when opening tabs:

:tabnew +92 sites/default/settings.php

and splitting:

:vsp +92 sites/default/settings.php

Increment/decrement number under the cursor

To increment:

CTRL+A

To decrement:

CTRL+X

Highlight all lines that don't begin with a certain character, # in the following example but contain some text:

/^[^#].\+$

Tags:

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.