June 2008 Entries

Vim + Firefox = Vimperator

 

Okay, so I've lamented about how I enjoy using Vim/gVim several times now. If you are still using notepad.exe as your text editor I strongly advise you to check out some of the other editors out on the market. Vim and Emacs tend to be near the top of the list, are full of features and are both extensible. The bottom line is that you need to find an editor, learn it and use it - it's that simple. In fact Dave Thomas and Andy Hunt discuss this in The Pragmatic Programmer. So, while I enjoy using the keystrokes within Vim to navigate text, what about web browsing - we all do that quite a bit these days? The mouse is the obvious choice, however it is not my only option. Enter Vimperator, suggested by Zed, a Firefox addin that allow your browser to act like Vim.

A quick introduction, once you have it installed I like to turn a few things back on so that it still feels like a normal web browser for the times when I actually do want to use my mouse. Like Vim, Vimperator is configurable through a file you can create titled "_vimperatorrc" which needs to be stored within your %userprofile% directory. This file allows you to customize the way Vimperator integrates with Firefox, etc. Below I have included the contents of my _vimperatorrc file to get you started.

 "Turn the menu and toolbar on.
:set guioptions+=mT

"Turn off the show tabs by default.
:set showtabline=1

"Turn session tracking off.
:set! browser.startup.page=1

"Allow user to click in address bar.
:set! browser.urlbar.clickSelectsAll=true
:set! browser.urlbar.doubleClickSelectsAll=true

"Map Ctrl + n for new windows
:map <C-n> <C-v><C-n>

"Map Ctrl + t for new tabs
:map <C-t> :tabopen<Enter>

"Map paste operation normally.
:imap <C-v> <C-v>


After you create this file you will need to restart Firefox and then the settings with be loaded. Standard navigation include:

  • j - down one line.
  • k - up one line.
  • o - open URL.
  • shift + h - navigate back 1 step in browser history.
  • shift + l - navigate forward 1 step in browser history.
  • f [number] - opens a link based on the number displayed on screen.
  • shift + f [number] - opens a link based on the number displayed on the screen (new tab).
  • gg - go to top of page.
  • shift + g - go to bottom of page.
  • ctrl + f - navigate down one screen length.
  • ctrl + b - navigate up one screen length.
  • b [number] - switches to the buffer (tab) based on the number supplied.
  • /[word] - search for [word], n goes to the next occurance, shift + n to the previous occurance.
If you want to read about the other options you can hit F1 or type :help.  You can grab a nightly build here.  One thing I didn't like about the default configuration within Vimperator was that it would track your session, so when you would close your browser, the next time you open Firefox, the site you were on was reloaded.  There are keyboard commands that will not save your session (i.e., ZQ), however there are many times I will simply close the Firefox window by mouse (old habits die hard).  Above in my configuration file I have turned off the session tracking.  I have found my web navigation experience has increased dramatically with this, and my reliance on the mouse continues to decrease.  Let me know if you decide to give it a try, it will defintely be worth your time.