Skip to content

Instantly share code, notes, and snippets.

@rpatterson
Last active February 24, 2020 03:22
Show Gist options
  • Save rpatterson/70387347ff1e924e75ddd339139a0ae7 to your computer and use it in GitHub Desktop.
Save rpatterson/70387347ff1e924e75ddd339139a0ae7 to your computer and use it in GitHub Desktop.
Emacs-Style Key Bindings for Vimium

My Vimium Key Bindings (Emacs-Style)

This is a full set of key bindings (as of Vimium v1.45); covering all Vimium functionality. I have tried to map all Vimium functionality to comparable Emacs functionality (whenever possible). In cases where there is no equivalent, those commands are prefixed by <c-g> (indicating <c-g>oogle Chrome; and because <c-g> does not conflict with other Emacs shortcuts at all).

Commented Shortcuts: There are a few Emacs-style shortcuts that are simply not possible in Vimium. All of my shortcuts (including those which were not possible; i.e. where I used a decent alternative) have been commented below. This should help to clarify my rationale.

Compatibility: All of these shortcuts were tested on Mac OS X (Mavericks). Please note that all of my shortcuts operate under the assumption that your Emacs Meta key is the Alt/Option key. This really was my only choice, because the key is already used in Chrome for shortcuts that come built into Chrome itself. Therefore, if you intend to use these shortcuts, I'd highly recommend that you use the Alt/Option key as your Emacs Meta key; helps with consistency. See also: my ~/.emacs to see how my modifier keys are configured in Emacs.

#########################################

unmapAll # Use Emacs-style bindings only.

#########################################

# Modifier Keys w/ Emacs Terminology:

# `<c-*>` = ⌃ Control Key; i.e. `C-*`.
# `<a-*>` = ⌥ Meta Key (Alt/Option); i.e. `M-*`.
# To clarify, `<a-*>` is `M-*` in the world of Emacs.

# `<m-*>` = ⌘ Command Key (prone to conflicts).
#   Avoid ⌘ key conflicts in Google Chrome.
#   It's good to avoid the ⌘ key altogether.
#   ~ See: http://bit.ly/VUvR7i

# The ⇧ Shift key is not used explicitly. However,
# all of these keyboard shortcuts are caSe-sensitive.
# Therefore, `<c-b>` is certainly NOT the same as `<c-B>`.
# Meaning, the ⇧ Shift key **is** necessary in some cases.
# You will also need the Shift key for things like `<a-}>`.

#########################################

# Similar to Emacs `(next|previous)-line`.
map <c-n> scrollDown
map <c-p> scrollUp

# Similar to Emacs `(backward|forward)-char`.
map <c-b> scrollLeft
map <c-f> scrollRight

# Similar to Emacs `(beginning|end)-of-buffer`.
map <a-<> scrollToTop
map <a->> scrollToBottom

# Identical to Emacs `scroll-(left|right)`.
map <c-x>< scrollToLeft
map <c-x>> scrollToRight

# Identical to `scroll-(down|up)-command`.
map <a-v> scrollFullPageUp
map <c-v> scrollFullPageDown

# Identical to Emacs `scroll-(up|down)-line`
# No KBD shortcut in Emacs by default, so not using.
# Similar to Emacs `(backward|forward)-paragraph`.
map <a-{> scrollPageUp
map <a-}> scrollPageDown

# Identical to Emacs `find-alternate-file`.
map <c-x><c-v> reload

# Not implemented in Emacs.
map <a-s> toggleViewSource

# Identical to Emacs `delete-window`.
map <c-x>0 removeTab

# Not implemented in Emacs.
map <c-g><c-u> copyCurrentUrl
map <c-g><c-l> LinkHints.activateModeToCopyLinkUrl

# Not implemented in Emacs.
map <c-g><c-o> openCopiedUrlInCurrentTab
map <c-g><c-O> openCopiedUrlInNewTab

# Not implemented in Emacs.
map <c-g>< goUp
map <c-g>/ goToRoot

# Not implemented in Emacs.
map <c-g><c-i> enterInsertMode

# Not implemented in Emacs.
map <c-g><c-f> focusInput

# Similar to Emacs `find-file`.
map <c-x><c-f> LinkHints.activateMode
map <c-x><c-F> LinkHints.activateModeToOpenInNewForegroundTab
map <c-x><a-f> LinkHints.activateModeWithQueue
map <c-x><a-F> LinkHints.activateModeToOpenInNewTab

# Similar to Emacs `list-directory`.
map <c-x><c-d> Vomnibar.activate
map <c-x><c-D> Vomnibar.activateInNewTab

# Similar to Emacs `switch-to-buffer`.
map <c-x>b Vomnibar.activateTabSelection

# Similar to Emacs `list-buffers`.
map <c-x><c-b> Vomnibar.activateBookmarks
map <c-x><c-B> Vomnibar.activateBookmarksInNewTab

# Not implemented in Emacs.
# Similar to Emacs `(previous|next)-buffer`.
# However, this uses `<c-g>` instead of `<c-x>`.
map <c-g><left> goPrevious
map <c-g><right> goNext

# Similar to Emacs `other-frame`.
# Also similar to Emacs `other-window`.
# The correct mapping is `<c-x>5o`, but not possible.
# Vimium doesn't support the `o` argument.
# Instead using `<c-x>o` here.
map <c-x>o nextFrame

# Similar to Emacs `set-mark-command`.
# Similar to Emacs `pop-global-mark`.
# Can't use `<c-<space>>` it conflicts w/ Chrome.
# In Chrome, `<space>` scrolls the current document.
# ------------------------------------------------------------------
# NOTE: both of these require that you enter a letter
# that you want to associate with a Vimium mark.
# e.g. `<c-@>` `a` ... and to return: `<c-x><c-@>` `a`.
# ------------------------------------------------------------------
map <c-@> Marks.activateCreateMode
map <c-x><c-@> Marks.activateGotoMode

# Similar to Emacs `isearch-forward`.
# Similar to Emacs `isearch-repeat-(forward|backward)`.
# ------------------------------------------------------------------
# NOTE: Vimium doesn't support repeated `<c-s>`.
# Instead, use `<a-S>` to move to next result.
# ------------------------------------------------------------------
# NOTE: Vimium requires that you press the `<enter>` key
# before shortcuts `<a-S>` and `<c-R>` will actually work.
# ------------------------------------------------------------------
map <c-s> enterFindMode
map <a-S> performFind
map <c-r> performBackwardsFind
map <c-R> performBackwardsFind

# Roughly map Vimium's "visual mode"
# to Emacs' `transient-mark-mode`.
map <a-@> enterVisualMode
map <c-x><a-@> enterVisualLineMode

# Not implemented in Emacs.
# Similar to Emacs `(backward|forward)-char`.
# However, this uses capitals w/ the shift key.
map <c-B> goBack
map <c-F> goForward

# Not implemented in Emacs.
# Similar to Emacs `(previous|next)-buffer`.
map <c-x><left> previousTab
map <c-x><right> nextTab

# Not implemented in Emacs.
# Similar to Emacs `(previous|next)-buffer`.
map <c-x><up> firstTab
map <c-x><down> lastTab

# Similar to Emacs `generate-new-buffer`.
# No KBD shortcut in Emacs by default.
map <c-g><c-t> createTab

# Similar to `clone-indirect-buffer-other-window`.
# The correct mapping is `<c-x>4c`, but not possible.
# Vimium doesn't support the `c` argument.
map <c-x>4 duplicateTab

# Not implemented in Emacs.
# Similar to Emacs `recover-file`.
# No KBD shortcut in Emacs by default.
map <c-g><c-r> restoreTab

# Similar to `make-frame-command`.
# The correct mapping is `<c-x>52`, but not possible.
# Vimium doesn't support the `2` argument.
map <c-x>5 moveTabToNewWindow

# Not implemented in Emacs.
# Similar to `set-window-dedicated-p`.
# No KBD shortcut in Emacs by default.
map <c-g><c-p> togglePinTab

# Not implemented in Emacs.
# Similar to `buff-move(left|right)`.
# See package: <http://bit.ly/Z1ZXYg>
# Also similar to: `(backward|forward)-word`
# However, this uses capitals w/ the shift key.
map <a-B> moveTabLeft
map <a-F> moveTabRight

# Similar to Emacs help commands.
map <c-h> showHelp

Vimium Help Screen w/ Emacs-Style Key Bindings


Original blog post: http://jaswsinc.com/my-vimium-key-bindings-emacs-style/

@rpatterson
Copy link
Author

<c-S> wasn't working for me to move forward through search matches, even after hitting <enter>, so I switched to <a-S> which is annoying but less annoying than always having to move backward through matches. I'm eager to find a better mapping if you have a suggestion.

@rpatterson
Copy link
Author

Using the keyboard instead of the mouse to copy text from web pages is probably the feature I want most from Vimium second only to opening links, so I added <a-@> for Vimium's enterVisualMode and <c-x><a-@> for enterVisualLineMode. Vimium doesn't support remapping the keys within visual mode, so we're stuck with vim movement keys once your in the mode. I'm eager to re-map the keys within visual mode if you have a suggestion.

Copy link

ghost commented Feb 24, 2020

This is just awesome, but is not working on my chrome as it has already been binded to open new window in chrome. How did you solve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment