Vim + Firefox = Vimperator

posted @ Monday, June 30, 2008 8:39 PM

 

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.
Comments
Fionn - 7/5/2008 10:34 AM
# re: Vim + Firefox = Vimperator
It's a shame that the vimperator's keybindings mess with the easy navigation at Gmail.

It's good though. But considering that I use vimperator while travelling (with the laptop, and I hate the touchpad - ugh!) and need the availability of Gmail, it's a real pain to have to disable/re-enable vim/vimperator so often.
sitaktif - 7/9/2008 8:20 AM
# re: Vim + Firefox = Vimperator
Do not forget Vimperator was there before Gmail's easy navigation...
Can't you rebind keys so that the keystrokes are compatible between the two?
Nick Parker - 7/9/2008 9:58 AM
# re: Vim + Firefox = Vimperator
You can either add a command to your _vimperatorrc file to test certain domain or enter pass through mode by pressing Ctrl + q. I've found that neither one work well with gmail.
Gmail - 10/7/2008 7:09 AM
# re: Vim + Firefox = Vimperator
You can use the regular HTML version of Gmail with Vimperator. Look for the link at the bottom of every Gmail page.
seren - 10/25/2008 3:02 AM
# re: Vim + Firefox = Vimperator
I use Ctrl-z when using Google maps or Gmail. This disables Vimperator until you hit Esc. Ctrl-v is handy too since it disables Vimperator just for the next keystroke.
Jon - 11/11/2008 6:58 PM
# re: Vim + Firefox = Vimperator
I use the following to configuration to persistently pass through keyboard events to gmail and google reader.

[quote]
:au LocationChange .* js modes.passAllKeys = /(www|mail)\.google\.com/.test(buffer.URL)
:au LocationChange .* js modes.passAllKeys = /google\.com\/reader/.test(buffer.URL)
[/quote]

(save with :mkv! of course)
Comments have been closed on this topic.