How to control Firefox using Vim keybindings By Joe 'Zonker' Brockmeier
on
June 22, 2007 (5:00:00 PM)
Share
Print
Comments
Vim
users stick with Vim in no small part because muscle memory is so
powerful -- once you've learned Vim's keybindings, it's possible to be
extremely productive in Vim without ever taking your hands off the
keyboard. If you'd like to imbue Firefox with Vim power, embrace the Vimperator extension. Vimperator turns Firefox into a no-nonsense, modal Web browser.
The Vimperator 0.4.1 extension is available on Mozdev.org.
To install the extension you can download it to your hard drive or just
click on the most recent version. You may need to add the site to your
allowed list of sites for installing extensions. Firefox will display a
bar at the top of the page if the site isn't on the allowed list --
just follow the prompts.
When you restart Firefox after installing Vimperator, you'll notice
that its menu bar, location bar, and the status bar have disappeared.
Vimperator replaces the default status bar with a custom status bar
that shows the command line and the current URL, and an indicator that
shows what tab you're in and where you're at in relation to the length
of the page. For instance, if you have five tabs open and you're
viewing the second tab, the status bar will display [2/5]
. If you're at the top of the page, it will display Top
, or Bot
at the bottom of the page. If you're at some spot in the middle, it will display an approximate percentage.
What if you just can't live without one of the Firefox toolbars that
Vimperator hides? No problem. As in Vim, you can enter commands in
Vimperator's "last line mode" by typing :
and the command. To modify the guioptions
settings and make the location and menu bars visible, type this command, then press Enter:
:set guioptions=mT
You should see the location bar (T
) and menu bar (m
) again. To bring back the bookmark bar, you could add b
, and s
for the original Firefox status bar.
Navigation
Vim and vi users will take to most of the Vimperator mappings right
away. The standard vi/Vim movement keys work as you'd expect: k
moves up, j
moves down, h
moves to the right, and l
moves to the left. To scroll to the top of the page, use gg
, and to move to the end of the page, use G
.
If you go to a page, like Google, that puts the cursor in a text
field, you'll be in insert mode rather than command mode. In that case,
if you try to use navigation keys or start a search, you'll just end up
typing text in the text field. You can press Tab
to move the cursor from the text field, or Esc
to move into command mode.
What about browsing? Vimperator has a full set of commands that will
help you navigate from the keyboard almost effortlessly. I won't
reproduce the entire list, but here's a sample to get you started:
gt
or Ctrl-n
: Go to the next tab.
gT
or Ctrl-p
: Go to the previous tab.
gh
: Go to your home page.
gH
: Go to your home page, in a new tab.
gu
: Go up. For example, would take you from http://www.example.com/blog/ to http://www.example.com/.
H
: Go to the previous page in your browser history.
L
: Go to the next page in your browser history.
:o http://www.example.com/
: Open http://www.example.com/.
:o search term
: Use the default search engine to search for a search term.
:o filename
: Open a local file using Firefox.
:q
: Close the current tab. If only one tab is open, exit Firefox.
zi
: Zoom in. Increases text size by 25% on the page that has focus.
zI
: Zoom in by 100% on the page that has focus.
zo
: Zoom out. Decreases text size by 25% on the page that has focus.
zO
: Zoom out by 100% on the page that has focus.
zz
: Used alone zz
will reset the page to 100%. Used with a count, it will set the text
size to any value between 25% and 500%. So, 105zz will set the text
size to 105% of normal.
Vimperator also sports a few Hint modes, where links have a yellow
label containing a shortcut to use the link. This is much like Konqueror's feature for keyboard navigation.
To enter QuickHint mode, press f
. Each link should have
a label, and you can activate the link by entering its shortcut. So, if
you're on a page with a dozen or so links, you'll have hints labeled A,
B, C, D, etc. If you press a
, you'll browse to that link. If you press A
, the link will be opened in a new tab in the background.
But wait, there's more! You can also use ;
to enter
what's called an ExtendedHint mode. You'll see the same labels, but
when you enter the shortcut, you'll just highlight the label. Once
you've selected a link, you can use y
to copy the URL, or Y
to copy the text description of the URL.
Browsing with Vimperator
One of Vimperator's most powerful features is the way it lets you handle Firefox history. If you use the :history
command, it will pull up the most recent 10 pages you've browsed. This includes local files as well as regular pages.
The default for history is to bring up only 10 pages, which isn't
too useful if you're looking for something from two days ago. You can
combine :history
with a search term to find URLs or page
names that match what you're looking for. Let's say you're trying to
find pages you've browsed with "craigslist" in the title or URL. Use :history craigslist
and Vimperator will display a preview window at the bottom of the
browser window with the most recent 10 pages that match "craigslist" in
the title or URL.
To browse to a page, double-click on the history entry you want in
the preview window. (Yes, right now there's no way to get there from
the keyboard.) To close the search result, type :pc
, or :pclose
, if that's easier to remember.
What about using bookmarks? To add a bookmark, use the :bmadd
command, and use :bmdel url
to delete a bookmark. You need to be very specific when you're using :mbdel
, as it will delete any bookmarks that match a URL.
The :bm
command displays bookmarks. Use :bm!
to open a page with all the bookmarks displayed, and a search bar at the top of the page. According to the help text, :bm expression
should allow you to search through your bookmarks, but this just
returns an error for me, so I suspect it's not fully implemented yet.
Searching
In Firefox, Ctrl-f
pops open the search dialog near the status bar. Using Vimperator, Ctrl-f
works as it would in Vim -- it moves you one "page" forward. The standard Vim search mapping, /
, works in Vimperator -- though the backward search mapping (?
) is not recognized.
Once you've entered a search term, you'll be taken to its first instance (if there is one). Unlike in Vim, you'll need to press Esc
to escape from the search field. To look for more instances of a search term, use n
to move forward through the search, and N
to move backward.
The search term is applied across all tabs, so if you search for XYZ in your first tab, and then use gt
to move to your second tab, you can still search that page for the same search term.
Getting help
Just as in Vim, you can get help for Vimperator by typing :help
at any time. This command will bring up a local copy of the Vimperator help document, which covers all the options, mappings, and commands that are used with Vimperator.
You can also, in some cases, go straight to the help for a specific
mapping. For example, if you want to see the reference for the :open
command, use :help :open
.
The problem with this is that you need to know the command you want to
use. It's fine as a reference, but not so good if you're not sure what
command to use to do something.
Quitting
When you're ready to exit Firefox, you can do so in a number of ways -- just as you can in Vim. Using :q
will exit Firefox if you're on the last tab. Otherwise, it closes the tab you're in.
Using :qall
or ZQ
will exit Firefox and
clear the session history. If you want to quit Firefox, but restart it
later with the same session, you can use ZZ
instead.
If you want to restart Firefox immediately, you can use the :restart
command.
Setting options
We've already covered using :set
to change some of Vimperator's options. The Vimperator help document includes a full list of options that can be set.
You can also set your defaults using a configuration file. To do
this, create a file called .vimperatorrc under your home directory.
Vimperator will check for this when it starts. The advantage to using a
configuration file is that it can reset options when Firefox starts.
For instance, if you don't like having the Firefox toolbar open, you
can set that in your .vimperatorrc and make sure it's not open when you
restart Firefox -- even if you had opened it during a previous session.
What you can and can't do with Vimperator's configuration file isn't well-documented yet, but you can use an example Vim syntax configuration that provides syntax highlighting for editing the .vimperatorrc file. Vimperator's developer, Martin Stubenschrott, has indicated
that users should wait for Vimperator 0.5 to do any scripting, as he's
planning to change and document the API at that time. You should also
be able to use :map
functions at that time.
Playing nice with others
Vimperator is an excellent extension, but it doesn't play well with
all of Firefox's features or extensions at this time, or with Web sites
that have navigation keys that conflict with Vimperator's mappings.
For example, when using Vimperator, the subscribe feed button in the
location bar doesn't seem to work, even when the location bar is set to
be visible using guioptions
. This is also true of the reload button, which is grayed out with Vimperator enabled. The default Firefox shortcut for reload, F5
, does not work, though you can use r
to refresh the page. Unfortunately, Vimperator doesn't have a shortcut
for the subscription feature, so it's not possible to easily subscribe
to a new feed using Firefox's subscription feature while Vimperator is
running.
Since Vimperator hides the default status bar, any extensions that
utilize the status bar are also affected. Google's Notebook extension,
for instance, is not disabled, but you can't open the notebook by
clicking the Notebook icon in the status bar. You can open it from the
Firefox context menu if you use the Note This menu entry to add a note
-- the Google Notebook pop-up will still work fine, it just doesn't
have a button in the status bar. Note that you can restore the default
Firefox status bar using :set guioptions=s
and it will appear on top of the Vimperator status bar.
Occasionally, Vimperator also conflicts with keybindings set by a
Web page. I thought, briefly, that I would have to choose between
Google Reader and Vimperator, because the navigation keys for
Vimperator and Google Reader conflict. However, Vimperator has a
solution for keybinding conflicts. You can press I
to ignore Vimperator's keybindings, and Esc
when you're ready to re-enter Vimperator mode. This doesn't fix
glitches like the subscription button, but at least it lets you use
applications like the feed reader without having to uninstall or
disable Vimperator.
In general, Vimperator's vi-like mappings integrate surprisingly
well with Firefox. For hard-core Vim junkies who hate having to use the
mouse except when absolutely necessary, Vimperator makes Firefox more
enjoyable.