Mac OS X like Alt-Tab Mouse Selection in Ubuntu

words by Brian Racer

I like how in OS X when I Alt-Tab I can pick a window or icon with a mouse click. I recently figured out how do get Ubuntu to perform in a similar fashion. First we need to install the CompizConfig Settings Manager (yes, you will need to be using compiz for this):

sudo apt-get install compizconfig-settings-manager

Next navigate the system menu to System -> Preferences -> CompizConfig Settings Manager. The app should start so next scroll down to the Window Management section and click on Static Application Switcher. Next click the Behavior tab and the last option will be ‘Allow Mouse Selection‘. Enable that check-box and exit the application.

It’s not quite as nice as OS X – you can only select by clicking, just mousing over won’t make each item the active target, but it’s better than nothing!

Optimize your PNG’s with OptiPNG

words by Brian Racer

Here is a quick shell command tip to run all your PNG files through the file size optimizer OptiPNG. Since PNG is a loss-less format quality stays exactly the same and file-size shrinks! I install optipng via MacPorts via the following command:

sudo port install optipng

In this example, public/images is the directory I want to search for PNG files:

find public/images/ -iname *.png -print0 |xargs -0 optipng -o7

The -o7 flag means it will try seven different compression techniques for each file and pick the best one. If it couldn’t do better, optipng will just leave the file alone and move on to the next.

If you just want to check if optipng will perform better compression but you don’t want it to modify your files yet just, add the -simulate parameter at the end.

Vim Tips for Ruby (and your wrists)

words by Brian Racer

Each time I am forced to type non-alpha-numeric characters during a coding session I feel that the flow and speed of my typing suffers. Not to mention depending on the size of your hands and how (im)properly you type, those keys can also put extra strain on your wrists. Since Ruby and Rails make extensive use of :symbols and hash-rockets ( => ) I felt the need to optimize their entry.

Hash-Rocket Insertion

" bind control-l to hashrocket
imap <C-l> <Space>=><Space>"

This emulates TextMate’s hash-rocket insertion. Just press Ctrl-L when in insert mode for a hash-rocket and leading quote to be inserted. Thanks to TechnicalPickles for this one.

If you use this with autoClose.vim the trailing quote will be inserted too. There are times when you don’t want quotes surrounding the hash value like booleans and symbols, so use surround.vim and type ds”. Poof! gone are the quotes.

Word to Symbol

" convert word into ruby symbol
imap <C-k> <C-o>b:<Esc>Ea
nmap <C-k> lbi:<Esc>E

This will turn any word into a symbol by prefixing it with a colon. It works in either Insert or Command mode. In command mode just place your cursor over the word and press Ctrl-k. While in Insert mode pressing Ctrl-k will convert the current word you are typing into a symbol.

You could probably make the argument it’s easier just to type the colon. To each his own but I have seen a lot of people who bend their right wrist to press both Shift and ; entirely with their right hand which puts strain on the wrist. Since symbols are often used right before the hash-rocket, chaining these two shortcuts can be a bit more fluid IMHO(the caret denotes the cursor position):

render action^<Ctrl-k><Ctrl-l>
# Will be transformed to
render :action => "^"

Symbol to Proc snippets

snippet collecta
snippet mapa

The collection.collect(&:symbol) is a great shortcut I use often in Rails, these snipMate.vim snippets make for less awkward entry.

Easy Command Mode Entry

" Easier non-interactive command insertion
nnoremap <Space> :

This one has nothing to do with Ruby, but instead of typing the colon every time to want to enter a new command in Command mode, just hit the spacebar!

Swap Esc and Caps-Lock

Another tip not specific to Ruby or even Vim really. I think using the Caps-Lock key as escape in Vim is the most efficient and quickest way to cancel some commands or exit certain modes. I prefer to swap them at the Operating System level rather than .vimrc hacks because I find the switch convenient in almost all applications, not just Vim. Consult Google to find out how to do it in your OS.


That’s it! If anyone has any other vim tips for ruby I would love to hear them! Also feel free to dig through my dotfiles and vimfiles to glean other tips.