Archive for the ‘Vim’ Category

Favorite Vim Tips

Posted on July 30th, 2010 in Vim | No Comments »

Quickly Indent Blocks Of Code

Vi Gang Sign

  1. Make sure you have :set cindent
  2. Put your cursor on an opening { or closing }
  3. Press =%
  4. All the code in the block is nicely indented

Searching Through Projects With vimgrep

Search through all the PHP files in a project.
1. Make sure you are at the root of your project in vim (type :pwd to see) if you are in the wrong dir then type :cd /path/to/project
2. :vimgrep pattern **/*.php

Examples:

Find the pattern “findMe” and don’t jump to the first match. Use the j flag to prevent jumping to the first match

:vimgrep /findMe/j **/*.php

Find the pattern “findMe” but match on case as well (not case-sensitive)

:vimgrep findMe\C **/*.php

Find the patter “findMe” without regard to case (case-insensitive)

:vimgrep findMe\c **/*.php

Organize With Pathogen

This is the best plugin ever for keeping your other vim plugins neat and
organized. Gone are the days of shotgunning doc and plugin files in multiple
directories. Now a plugin and all its related files can stay together.
Go here to get pathogen from vim.org

Vim: How To Fold Functions

Posted on March 20th, 2009 in Everyday Tips, PHP, Vim, Web Development | No Comments »

Vi Gang Sign

The is really a tip on how to fold any code block including functions. Navigate your cursor somewhere inside of the code block you want to fold, make sure you are in command/normal mode (press escape if you need to) then type zfa}

To save your folds between vim sessions you need to issue the command :mkview otherwise when you close vim your folds will be lost (your folds, not your code). To make life easier on you, you can have your folds automatically saved for you by adding this to your .vimrc file

au BufWinLeave * mkview
au BufWinEnter * silent loadview

Recursive searching in vim with grep – vimgrep

Posted on February 17th, 2009 in Everyday Tips, PHP, Ubuntu, Vim, Web Development | 1 Comment »

Vi Gang Sign

One of the smartest people I’ve ever digitally met, Ryan Paul, taught me this awesome tip for doing a project wide search in vim. I needed to look for all occurrences of the patter _Models_ in a PHP project I was working on and you can do it right inside of vim – the best text editor ever invented.

  1. Open vim and make sure you are in the top level folder of your project by typing :pwd
  2. Then type :vimgrep YourPattern **/*.php
  3. To open your search results in their own buffer type :copen

The **/ recursively searches through all your directories for you pattern. :copen opens the search results in their own buffer. You can use the arrow keys to move up and down through the list and hit enter to have it open that result in the main buffer. You can also use :cnext and :cprev to move to the next and previous items in the list. Perhaps you might bind those to keyboard shortcuts so you can move through the search results quickly.

Vim Uppercase & Lowercase

Posted on August 29th, 2007 in Everyday Tips, Ubuntu, Vim | 7 Comments »

I have been using vim for a couple years and every week it seems I learn some new feature or trick you can do. Recently I learned how to convert a selection to either all uppercase or all lowercase letters.

Convert a visual selection to all uppercase letters.

gU

Convert to lowercase letters

gu
Get Adobe Flash playerPlugin by wpburn.com wordpress themes