Skip to content

rachidbch/chromium-vim

 
 

Repository files navigation

#What is cVim?

Vim for Google Chrome. I hate using the mouse, especially after learning Vim. With my desktop (Linux), I have a lot of key bindings that make doing things easier: I open Chrome with Alt+w, I close a window with Alt+Shift+d, I open a terminal with Alt+t. This is harder to do with Chrome because it has no section for customizing keyboard shortcuts, and it is still necessary to use the mouse to do things like click links. cVim aims to eliminate this problem as best as the Chrome extensions API will allow it to.

#Where can I get cVim?

  • There are two ways:
  • You can install it through the Chrome web store
  • You can download the .zip file here and enable cVim by going to the chrome://extensions URL and checking developer mode, then pointing Chrome to the unzipped folder via the Load unpacked extensions... button.

Why is this different than Vimium, ViChrome, or Vrome?

These extensions do a wonderful job of adding Vim-like keybindings to Google Chrome, but they lack many of the features that Firefox Addon, Pentadactyl, have.

  • What features does cVim add to Chrome?
  • Google/IMDB/Wikipedia/Amazon/Duckduckgo/Yahoo/Bing search completion
  • Support for custom search engines
  • History and Bookmark search/completion with bookmark folder support
  • Caret/Visual mode
  • Efficient link hints (with support for custom mappings)
  • Support for custom keyboard mappings
  • Regex page search with highlighting
  • Command bar with tab-completion
  • Smooth scrolling

#cVim Help ###cVimrc

  • Boolean cVimrc settings are enabled with the command 'set' + <SETTING_NAME> and disabled with the command 'set' + no<SETTING_NAME> (for example, set regexp and set noregexp)
  • Boolean cVimrc settings can be inversed by adding "!" to the end
  • Other settings are defined with = used as a separator and are prefixed by let (for example, let hintcharacters="abc")
setting type description default
searchlimit integer set the amount of results displayed in the command bar 20
scrollstep integer set the amount of pixels scrolled when using the scrollUp and scrollDown commands 75
timeoutlen integer The amount of time to wait for a <Leader> mapping in milliseconds 1000
fullpagescrollpercent integer set the percent of the page to be scrolled by when using the scrollFullPageUp and scrollFullPageDown commands 85
typelinkhintsdelay integer the amount of time (in milliseconds) to wait before taking input after opening a link hint with typelinkhints and numerichints enabled 500
scrollduration integer the duration of smooth scrolling 20
zoomfactor integer the step size when zooming the page in/out 0.1
hud boolean show the heads-up-display true
regexp boolean use regexp in find mode true
ignorecase boolean ignore search case in find mode true
linkanimations boolean show fade effect when link hints open and close false
numerichints boolean use numbers for link hints instead of a set of characters false
dimhintcharacters boolean dim letter matches in hint characters rather than remove them from the hint true
defaultnewtabpage boolean use the default chrome://newtab page instead of a blank page false
cncpcompletion boolean use and to cycle through completion results (requires you to set the nextCompletionResult keybinding in the chrome://extensions page (bottom right) false
smartcase boolean case-insensitive find mode searches except when input contains a capital letter true
incsearch boolean begin auto-highlighting find mode matches when input length is greater thant two characters true
typelinkhints boolean (numerichints required) type text in the link to narrow down numeric hints false
autohidecursor boolean hide the mouse cursor when scrolling (useful for Linux, which doesn't auto-hide the cursor on keydown) false
autofocus boolean allows websites to automatically focus an input box when they are first loaded true
insertmappings boolean use insert mappings to navigate the cursor in text boxes (see bindings below) true
smoothscroll boolean use smooth scrolling true
autoupdategist boolean if a GitHub Gist is used to sync settings, pull updates every hour (and when Chrome restarts) false
completionengines array of strings use only the specified search engines []
blacklists array of strings disable cVim on the sites matching one of the patterns []
mapleader string The default <Leader> key \
highlight string the highlight color in find mode "#ffff00"
defaultengine string set the default search engine "google"
locale string set the locale of the site being completed/searched on (see example configuration below) ""
activehighlight string the highlight color for the current find match "#ff9632"
homedirectory string the directory to replace ~ when using the file command ""
qmark <alphanumeric charcter> string add a persistent QuickMark (e.g. let qmark a = ["http://google.com", "http://reddit.com"]) none
previousmatchpattern string (regexp) the pattern looked for when navigating a page's back button ((?!last)(prev(ious)?|back|«|less|<|‹| )+)
nextmatchpattern string (regexp) the pattern looked for when navigation a page's next button ((?!first)(next|more|>|›|»|forward| )+)
hintcharacters string (alphanumeric) set the default characters to be used in link hint mode "asdfgqwertzxcvb"
barposition string <br>["top", "bottom"] set the default position of the command bar "top"

###Example configuration

" Settings
set nohud
set nosmoothscroll
set noautofocus "The opposite of autofocus; this setting stops sites from focusing on an input box when they load
set typelinkhints
let searchlimit = 30
let scrollstep = 70
let barposition = "bottom"
let locale = "uk" "Current choices are 'jp' and 'uk'. This allows cVim to use sites like google.co.uk or google.co.jp to search rather than google.com. Support is currently very limited. Let me know if you need a different locale for one of the completion/search engines
let hintcharacters = "abc123"
let searchengine dogpile = "http://www.dogpile.com/search/web?q=%s" "If you leave out the '%s' at the end of the URL, your query will be appended to the link. Otherwise, your query will replace the '%s'.
let completionengines = ["google", "amazon", "imdb", "dogpile"]
let searchalias g = "google" "Create a shortcut for search engines. For example, typing ':tabnew g example' would act the same way as ':tabnew google example'
let qmark a = ["http://www.reddit.com", "http://www.google.com", "http://twitter.com"]  "Open all of these in a tab with `gnb` or open one of these with <N>goa where <N>
let blacklists = ["https://mail.google.com/*", "*://mail.google.com/*"]
let mapleader = ","

" Mappings

map <Leader>r reloadTabUncached
map <Leader>x :restore<Space>

"This remaps the default 'j' mapping
map j scrollUp

"You can use <Space>, which is interpreted as a literal " " character, to enter buffer completion mode
map gb :buffer<Space>

"The unmaps the default 'k' mapping
unmap k

"This remaps the default 'f' mapping to the current 'F' mapping
map f F

"Toggle the current HUD display value
map <C-h> :set hud!<CR>

"Switch between alphabetical hint characters and numeric hints
map <C-i> :set numerichints!<CR>

map <C-u> rootFrame
map <M-h> previousTab
map <C-d> scrollPageDown
map <C-e> scrollPageUp
iunmap <C-y>
imap <C-m> deleteWord

" Create a variable that can be used/referenced in the command bar
let @@reddit_prog = 'http://www.reddit.com/r/programming'
let @@top_all = 'top?sort=top&t=all'
let @@top_day = 'top?sort=top&t=day'

" TA binding opens 'http://www.reddit.com/r/programming/top?sort=top&t=all'
" in a new tab
map TA :to @@reddit_prog/@@top_all<CR>
map TD :to @@reddit_prog/@@top_day<CR>

###Blacklists

###Site-specific Configuration

  • You can enable certain rc settings for sites using the blacklist match pattern as described above
" this will enable the config block below on the domain 'reddit.com'
site '*://*.reddit.com/*' {
      unmap j
      unmap k
      set numerichints
}

###Running commands when a page loads

  • In a similar fashion to the site-specific configuration described above, cVim can run commands when a page is loaded with the call keyword
" In this case, when pages with a file ending in ".js" are loaded,
" cVim will pin the tab and then scroll down
site '*://*/*.js' {
      call :pintab
      call scrollDown
}

###Mappings

  • Normal mappings are defined with the following structure: map <KEY> <MAPPING_NAME>
  • Insert mappings use the same structure, but use the command "imap" instead of "map"
  • Control, meta, and alt can be used also:
<C-u> "Ctrl + u
<M-u> "Meta + u
<A-u> "Alt  + u
  • It is also possible to unmap default bindings with unmap <KEY> and insert bindings with iunmap <KEY>
  • To unmap all default keybindings, use unmapAll. To unmap all default insert bindings, use iunmapAll

###Tabs

  • Commands that open links (:tabnew and :open) have three different properties
  • ! => Open in a new tab
  • & => Open in a new tab (inactive/unfocused)
  • * => Pin the tab
  • ? => Treat the query as a search
  • = => Treat the query as a URL
  • The use of these properties are best explained with examples:
:open! google<CR> "This is the same as :tabnew google<CR>
:open google!<CR> "This is another way of writing the above (these flags can can be added to either the base command or the end of the final command)

:open& google<CR> "This will open Google in a new inactive tab

:open&* google<CR> "The will open Google in a new inactive, pinned tab
:tabnew google&*<CR> "Once again, this will do the same thing as the above command
:open google&*<CR> "Again, same as above

:open google!& "Here, the & flag will cancel out the ! flag, opening Google in a new inactive tab

"More examples
:bookmarks my_bookmark.com& "inactive,new tab
:bookmarks&* my_bookmark.com "inactive,pinned,new tab
:bookmarks! my_bookmark.com "new tab
:bookmarks my_bookmark.com "same tab

#Keybindings

Movement Mapping name
j, s scroll down scrollDown
k, w scroll up scrollUp
h scroll left scrollLeft
l scroll right scrollRight
d scroll half-page down scrollPageDown
unmapped scroll full-page down scrollFullPageDown
u, e scroll half-page up scrollPageUp
unmapped scroll full-page up scrollFullPageUp
gg scroll top the top of the page scrollToTop
G scroll to the bottom of the page scrollToBottom
0 scroll to the left of the page scrollToLeft
$ scroll to the right of the page scrollToRight
gi go to first input box goToInput
gI go to the last focused input box by gi goToLastInput
zz center page to current search match (middle) centerMatchH
zt center page to current search match (top) centerMatchT
zb center page to current search match (bottom) centerMatchB
Link Hints
f open link in current tab createHint
F open link in new tab createTabbedHint
unmapped open link in new tab (active) createActiveTabbedHint
W open link in new window createHintWindow
A repeat last hint command openLastHint
q trigger a hover event (mouseover + mouseenter) createHoverHint
Q trigger a unhover event (mouseout + mouseleave) createUnhoverHint
mf open multiple links createMultiHint
mr reverse image search multiple links multiReverseImage
my yank multiple links (open the list of links with P) multiYankUrl
gy copy url from link to clipboard yankUrl
gr reverse image search (google images) reverseImage
; change the link hint focus
QuickMarks
M<*> create quickmark <*> addQuickMark
go<*> open quickmark <*> in the current tab openQuickMark
gn<*> open quickmark <*> in a new tab <N> times openQuickMarkTabbed
Miscellaneous
a alias to ":tabnew google " :tabnew google
. repeat the last command repeatCommand
: open command bar openCommandBar
<A-z> toggle cVim (same as disable cVim option in toolbar icon) toggleCvim
unmapped toggle the blacklist on the current domain toggleBlacklisted
/ open search bar openSearchBar
? open search bar (reverse search) openSearchBarReverse
I search through browser history :history
<N>g% scroll <N> percent down the page percentScroll
zr restart Google Chrome :chrome://restart<CR>
i enter insert mode (escape to exit) insertMode
r reload the current tab reloadTab
gR reload the current tab + local cache reloadTabUncached
;<*> create mark <*> setMark
'' go to last scroll position lastScrollPosition
'<*> go to mark <*> goToMark
none reload all tabs reloadAllTabs
cr reload all tabs but current reloadAllButCurrent
zi zoom page in zoomPageIn
zo zoom page out zoomPageOut
z0 zoom page to original size zoomOrig
z<Enter> toggle image zoom (same as clicking the image on image-only pages) toggleImageZoom
gd alias to :chrome://downloads<CR> :chrome://downloads<CR>
yy copy the url of the current page to the clipboard yankDocumentUrl
b search through bookmarks :bookmarks
p open the clipboard selection openPaste
P open the clipboard selection in a new tab openPasteTab
gj hide the download shelf hideDownloadsShelf
gf cycle through iframes nextFrame
gF go to the root frame rootFrame
gq stop the current tab from loading cancelWebRequest
gQ stop all tabs from loading cancelAllWebRequests
gu go up one path in the URL goUpUrl
gU go to to the base URL goToRootUrl
gs go to the view-source:// page for the current Url goToSource
<C-b> create or toggle a bookmark for the current URL createBookmark
unmapped close all browser windows quitChrome
Tab Navigation
gt, K, R navigate to the next tab nextTab
gT, J, E navigate to the previous tab previousTab
g0, g$ go to the first/last tab firstTab, lastTab
<C-S-h>, gh open the last URL in the current tab's history in a new tab openLastLinkInTab
<C-S-l>, gl open the next URL from the current tab's history in a new tab openNextLinkInTab
x close the current tab closeTab
gxT close the tab to the left of the current tab closeTabLeft
gxt close the tab to the right of the current tab closeTabRight
gx0 close all tabs to the left of the current tab closeTabsToLeft
gx$ close all tabs to the right of the current tab closeTabsToRight
X open the last closed tab lastClosedTab
t :tabnew :tabnew
T :tabnew <CURRENT URL> :tabnew @%
O :open <CURRENT URL> :open @%
<N>% switch to tab <N> goToTab
H, S go back goBack
L, D go forward goForward
B search for another active tab :buffer
< move current tab left moveTabLeft
> move current tab right moveTabRight
]] click the "next" link on the page (see nextmatchpattern above) nextMatchPattern
[[ click the "back" link on the page (see previousmatchpattern above) previousMatchPattern
gp pin/unpin the current tab pinTab
<C-6> toggle the focus between the last used tabs lastUsedTab
Find Mode
n next search result nextSearchResult
N previous search result previousSearchResult
v enter visual/caret mode (highlight current search/selection) toggleVisualMode
V enter visual line mode from caret mode/currently highlighted search toggleVisualLineMode
Visual/Caret Mode
<Esc> exit visual mode to caret mode/exit caret mode to normal mode
v toggle between visual/caret mode
h, j, k, l move the caret position/extend the visual selection
y copys the current selection
n select the next search result
N select the previous search result
p open highlighted text in current tab
P open highlighted text in new tab
Text boxes
<C-i> move cursor to the beginning of the line beginningOfLine
<C-e> move cursor to the end of the line endOfLine
<C-u> delete to the beginning of the line deleteToBeginning
<C-o> delete to the end of the line deleteToEnd
<C-y> delete back one word deleteWord
<C-p> delete forward one word deleteForwardWord
<C-h> move cursor back one word backwardWord
<C-l> move cursor forward one word forwardWord
<C-f> move cursor forward one letter forwardChar
<C-b> move cursor back one letter backwardChar

#Command Mode

Command Description
:tabnew (autocomplete) open a new tab with the typed/completed search
:new (autocomplete) open a new window with the typed/completed search
:open (autocomplete) open the typed/completed url/google search
:history (autocomplete) search through browser history
:bookmarks (autocomplete) search through bookmarks
:bookmarks /<folder> (autocomplete) browse bookmarks by folder/open all bookmarks from folder
:set (autocomplete) temporarily change a cVim setting
:chrome:// (autocomplete) open a chrome:// url
:tabhistory (autocomplete) browse the different history states of the current tab
:quit close the current tab
:qall close the current window
:restore (autocomplete) restore a previously closed tab (newer versions of Chrome only)
:tabattach (autocomplete) move the current tab to another open window
:tabdetach move the current tab to a new window
:file (autocomplete) [expirimental] open a local file
:duplicate duplicate the current tab
:settings open the settings page
:nohlsearch clear the highlighted text from the last search
:execute execute a sequence of keys (Useful for mappings. For example, "map j :execute 2j")
:buffer (autocomplete) change to a different tab
:mksession create a new session from the current tabs in the active window
:delsession (autocomplete) delete a saved session
:session (autocomplete) open the tabs from a saved session in a new window
:script run JavaScript on the current page
:togglepin toggle the pin state of the current tab
:pintab pin the current tab
:unpintab unpin the current tab

#Tips

  • You can use @% in "open" commands to specify the current URL. For example, ":open @%" would essentially refresh the current page.
  • Prepend a number to the command to repeat that command N times
  • Use the up/down arrows in command/find mode to navigate through previously executed commands/searches -- you can also use this to search for previously executed commands starting with a certain combination of letters (for example, entering "ta" in the command bar and pressing the up arrow will search command history for all matches beginning with "ta"

Contributing

Nice that you want to spend some time improving this extension. Solving issues is always appreciated. If you're going to add a feature, it would be best to submit an issue. You'll get feedback whether it will likely be merged.

  1. Run npm install in the repository's root folder
  2. Run make
  3. Navigate to chrome://extensions
  4. Toggle into Developer Mode
  5. Click on "Load Unpacked Extension..."
  6. Select the cVim directory.

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 95.1%
  • CSS 4.4%
  • Other 0.5%