API.md
November 29, 2025 ยท View on GitHub
Table of Contents
- mapkey
- vmapkey
- imapkey
- map
- unmap
- unmapAllExcept
- imap
- iunmap
- cmap
- vmap
- vunmap
- lmap
- addSearchAlias
- removeSearchAlias
- searchSelectedWith
- Clipboard.read
- Clipboard.write
- Hints.setNumeric
- Hints.setCharacters
- Hints.dispatchMouseClick
- Hints.click
- Hints.create
- Hints.style
- Normal.passThrough
- Normal.scroll
- Normal.feedkeys
- Normal.jumpVIMark
- Visual.style
- Front.showEditor
- Front.openOmnibar
- Front.registerInlineQuery
- RUNTIME
- aceVimMap
- addVimMapKey
- getBrowserName
- Front.showBanner
- Front.showPopup
- isElementPartiallyInViewport
- getLargeElements
- getClickableElements
- tabOpenLink
mapkey
Create a shortcut in normal mode to execute your own action.
Parameters
keysstring the key sequence for the shortcut.annotationstring a help message to describe the action, which will displayed in help opened by?.jscodefunction a Javascript function to be bound. If the function needs an argument, next pressed key will be fed to the function.optionsobjectdomain: regex, a Javascript regex pattern to identify the domains that this mapping works, for example,/github\.com/isays that this mapping works only for github.com,repeatIgnore: boolean, whether this action can be repeated by dot command. (optional, defaultnull)
Examples
mapkey("<Space>", "pause/resume on youtube", function() {
var btn = document.querySelector("button.ytp-ad-overlay-close-button") || document.querySelector("button.ytp-ad-skip-button") || document.querySelector('ytd-watch-flexy button.ytp-play-button');
btn.click();
}, {domain: /youtube.com/i});
vmapkey
- See: mapkey
Create a shortcut in visual mode to execute your own action.
Parameters
keysstring the key sequence for the shortcut.annotationstring a help message to describe the action, which will displayed in help opened by?.jscodefunction a Javascript function to be bound. If the function needs an argument, next pressed key will be fed to the function.optionsobjectdomain: regex, a Javascript regex pattern to identify the domains that this mapping works, for example,/github\.com/isays that this mapping works only for github.com,repeatIgnore: boolean, whether this action can be repeated by dot command. (optional, defaultnull)
imapkey
- See: mapkey
Create a shortcut in insert mode to execute your own action.
Parameters
keysstring the key sequence for the shortcut.annotationstring a help message to describe the action, which will displayed in help opened by?.jscodefunction a Javascript function to be bound. If the function needs an argument, next pressed key will be fed to the function.optionsobjectdomain: regex, a Javascript regex pattern to identify the domains that this mapping works, for example,/github\.com/isays that this mapping works only for github.com,repeatIgnore: boolean, whether this action can be repeated by dot command. (optional, defaultnull)
map
Map a key sequence to another in normal mode.
Parameters
new_keystrokestring a key sequence to replaceold_keystrokestring a key sequence to be replaceddomainregex a Javascript regex pattern to identify the domains that this mapping works. (optional, defaultnull)new_annotationstring use it instead of the annotation from old_keystroke if provided. (optional, defaultnull)
Examples
map(';d', '<Ctrl-Alt-d>');
unmap
Unmap a key sequence in normal mode.
Parameters
keystrokestring a key sequence to be removed.domainregex a Javascript regex pattern to identify the domains that this mapping will be removed. (optional, defaultnull)
Examples
unmap("<<", /youtube.com/);
unmapAllExcept
Unmap all keybindings except those specified.
Parameters
keystrokesarray the keybindings you want to keep.domainregex a Javascript regex pattern to identify the domains that this mapping will be removed. (optional, defaultnull)
Examples
unmapAllExcept(['E','R','T'], /google.com|twitter.com/);
imap
- See: map
Map a key sequence to another in insert mode.
Parameters
new_keystrokestring a key sequence to replaceold_keystrokestring a key sequence to be replaceddomainregex a Javascript regex pattern to identify the domains that this mapping works. (optional, defaultnull)new_annotationstring use it instead of the annotation from old_keystroke if provided. (optional, defaultnull)
iunmap
- See: unmap
Unmap a key sequence in insert mode.
Parameters
keystrokestring a key sequence to be removed.domainregex a Javascript regex pattern to identify the domains that this mapping will be removed. (optional, defaultnull)
cmap
- See: map
Map a key sequence to another in omnibar.
Parameters
new_keystrokestring a key sequence to replaceold_keystrokestring a key sequence to be replaceddomainregex a Javascript regex pattern to identify the domains that this mapping works. (optional, defaultnull)new_annotationstring use it instead of the annotation from old_keystroke if provided. (optional, defaultnull)
vmap
- See: map
Map a key sequence to another in visual mode.
Parameters
new_keystrokestring a key sequence to replaceold_keystrokestring a key sequence to be replaceddomainregex a Javascript regex pattern to identify the domains that this mapping works. (optional, defaultnull)new_annotationstring use it instead of the annotation from old_keystroke if provided. (optional, defaultnull)
vunmap
- See: unmap
Unmap a key sequence in visual mode.
Parameters
keystrokestring a key sequence to be removed.domainregex a Javascript regex pattern to identify the domains that this mapping will be removed. (optional, defaultnull)
lmap
- See: map
Map a key sequence to another in lurk mode.
Parameters
new_keystrokestring a key sequence to replaceold_keystrokestring a key sequence to be replaceddomainregex a Javascript regex pattern to identify the domains that this mapping works. (optional, defaultnull)new_annotationstring use it instead of the annotation from old_keystroke if provided. (optional, defaultnull)
addSearchAlias
Add a search engine alias into Omnibar.
Parameters
aliasstring the key to trigger this search engine, one or several chars, used as search alias, when you input the string and pressspacein omnibar, the search engine will be triggered.promptstring a caption to be placed in front of the omnibar.search_urlstring the URL of the search engine, for example,https://www.s.com/search.html?query=, if there are extra parameters for the search engine, you can use it ashttps://www.s.com/search.html?query={0}&type=csorhttps://www.s.com/search.html?type=cs&query=(since order of URL parameters usually does not matter).search_leader_keystring<search_leader_key><alias>in normal mode will search selected text with this search engine directly without opening the omnibar, for examplesd. (optional, defaults)suggestion_urlstring the URL to fetch suggestions in omnibar when this search engine is triggered. (optional, defaultnull)callback_to_parse_suggestionfunction a function to parse the response fromsuggestion_urland return a list of strings as suggestions. Receives two arguments:response, the first argument, is an object containing a propertytextwhich holds the text of the response; andrequest, the second argument, is an object containing the propertiesquerywhich is the text of the query andurlwhich is the formatted URL for the request. (optional, defaultnull)only_this_site_keystring<search_leader_key><only_this_site_key><alias>in normal mode will search selected text within current site with this search engine directly without opening the omnibar, for examplesod. (optional, defaulto)optionsobjectfavicon_urlURL for favicon for this search engine,skipMapsiftruedisable creating key mappings for this search engine (optional, defaultnull)
Examples
addSearchAlias('d', 'duckduckgo', 'https://duckduckgo.com/?q=', 's', 'https://duckduckgo.com/ac/?q=', function(response) {
var res = JSON.parse(response.text);
return res.map(function(r){
return r.phrase;
});
});
removeSearchAlias
Remove a search engine alias from Omnibar.
Parameters
aliasstring the alias of the search engine to be removed.search_leader_keystring<search_leader_key><alias>in normal mode will search selected text with this search engine directly without opening the omnibar, for examplesd. (optional, defaults)only_this_site_keystring<search_leader_key><only_this_site_key><alias>in normal mode will search selected text within current site with this search engine directly without opening the omnibar, for examplesod. (optional, defaulto)
Examples
removeSearchAlias('d');
searchSelectedWith
Search selected with.
Parameters
sestring a search engine's search URLonlyThisSiteboolean whether to search only within current site, need support from the provided search engine. (optional, defaultfalse)interactiveboolean whether to search in interactive mode, in case that you need some small modification on the selected content. (optional, defaultfalse)aliasstring only used with interactive mode, in such case the url fromseis ignored, SurfingKeys will construct search URL from the alias registered byaddSearchAlias. (optional, default"")
Examples
searchSelectedWith('https://translate.google.com/?hl=en#auto/en/');
Clipboard.read
Read from clipboard.
Parameters
onReadyfunction a callback function to handle text read from clipboard.
Examples
Clipboard.read(function(response) {
console.log(response.data);
});
Clipboard.write
Write text to clipboard.
Parameters
textstring the text to be written to clipboard.
Examples
Clipboard.write(window.location.href);
Hints.setNumeric
Use digits as hint label, with it set you could type text to filter links, this API is to replace original setting like Hints.numericHints = true;.
Examples
Hints.setNumeric();
Hints.setCharacters
Set characters for generating hints, this API is to replace original setting like Hints.characters = "asdgqwertzxcvb";.
Parameters
charactersstring the characters for generating hints.
Examples
Hints.setCharacters("asdgqwertzxcvb");
Hints.dispatchMouseClick
- See: Hints.create
The default onHintKey implementation.
Parameters
elementHTMLElement the element for which the pressed hint is targeted.
Examples
mapkey('q', 'click on images', function() {
Hints.create("div.media_box img", Hints.dispatchMouseClick);
}, {domain: /weibo.com/i});
Hints.click
Click element or create hints for elements to click.
Parameters
linksstring or array of HTMLElement, click on it if there is only one in the array orforceparameter is true, otherwise hints will be generated for them. Iflinksis a string, it will be used as css selector forgetClickableElements.forceboolean force to click the first input element whether there are more than one elements inlinksor not. (optional, defaultfalse)
Examples
mapkey('zz', 'Hide replies', function() {
Hints.click(document.querySelectorAll("#less-replies:not([hidden])"), true);
});
Hints.create
- See: Hints.dispatchMouseClick
Create hints for elements to click.
Parameters
cssSelectorstring or array of HTMLElement, iflinksis a string, it will be used as css selector.onHintKeyfunction a callback function on hint keys pressed.attrsobjectactive: whether to activate the new tab when a link is opened,tabbed: whether to open a link in a new tab,multipleHits: whether to stay in hints mode after one hint is triggered. (optional, defaultnull)
Examples
mapkey('yA', '#7Copy a link URL to the clipboard', function() {
Hints.create('*[href]', function(element) {
Clipboard.write('[' + element.innerText + '](' + element.href + ')');
});
});
Returns Promise which will be resolved how many hints are created.
Hints.style
Set styles for hints.
Parameters
cssstring styles for hints.modestring sub mode for hints, usetextfor hints mode to enter visual mode. (optional, defaultnull)
Examples
Hints.style('border: solid 3px #552a48; color:#efe1eb; background: none; background-color: #552a48;');
Hints.style("div{border: solid 3px #707070; color:#efe1eb; background: none; background-color: #707070;} div.begin{color:red;}", "text");
Normal.passThrough
Enter PassThrough mode.
Parameters
timeoutnumber? how many milliseconds to linger in PassThrough mode, to ignore it will stay in PassThrough mode until an Escape key is pressed.
Normal.scroll
Scroll within current target.
Parameters
typestring down | up | pageDown | fullPageDown | pageUp | fullPageUp | top | bottom | left | right | leftmost | rightmost | byRatio
Normal.feedkeys
Feed keys into Normal mode.
Parameters
keysstring the keys to be fed into Normal mode.
Normal.jumpVIMark
Jump to a vim-like mark.
Parameters
markstring a vim-like mark.
Visual.style
Set styles for visual mode.
Parameters
Examples
Visual.style('marks', 'background-color: #89a1e2;');
Visual.style('cursor', 'background-color: #9065b7;');
Front.showEditor
Launch the vim editor.
Parameters
elementHTMLElement the target element which the vim editor is launched for, this parameter can also be a string, which will be used as default content in vim editor.onWritefunction a callback function to be executed on written back from vim editor.typestring the type for the vim editor, which can beurl, if not provided, it will be tag name of the target element. (optional, defaultnull)useNeovimboolean the vim editor will be the embeded JS implementation, ifuseNeovimis true, neovim will be used through natvie messaging. (optional, defaultfalse)
Examples
mapkey(';U', '#4Edit current URL with vim editor, and reload', function() {
Front.showEditor(window.location.href, function(data) {
window.location.href = data;
}, 'url');
});
Front.openOmnibar
Open the omnibar.
Parameters
argsobjecttypethe sub type for the omnibar, which can beBookmarks,AddBookmark,History,URLs,RecentlyClosed,TabURLs,Tabs,Windows,VIMarks,SearchEngine,Commands,OmniQueryandUserURLs.
Examples
mapkey('ou', '#8Open AWS services', function() {
var services = Array.from(top.document.querySelectorAll('#awsc-services-container li[data-service-href]')).map(function(li) {
return {
title: li.querySelector("span.service-label").textContent,
url: li.getAttribute('data-service-href')
};
});
if (services.length === 0) {
services = Array.from(top.document.querySelectorAll('div[data-testid="awsc-nav-service-list"] li[data-testid]>a')).map(function(a) {
return {
title: a.innerText,
url: a.href
};
});
}
Front.openOmnibar({type: "UserURLs", extra: services});
}, {domain: /console.amazonaws|console.aws.amazon.com/i});
Front.registerInlineQuery
- See: example.
Register an inline query.
Parameters
argsobjecturl: string or function, the dictionary service url or a function to return the dictionary service url,parseResult: function, a function to parse result from dictionary service and return a HTML string to render explanation,headers: object[optional], in case your dictionary service needs authentication.
RUNTIME
Call background action with args, the callback will be executed with response from background.
Parameters
actionstring a background action to be called.argsobject the parameters to be passed to the background action.callbackfunction a function to be executed with the result from the background action.
Examples
RUNTIME('getTabs', {queryInfo: {currentWindow: true}}, response => {
console.log(response);
});
aceVimMap
Map the key sequence lhs to rhs for mode ctx in ACE editor.
Parameters
lhsstring a key sequence to replacerhsstring a key sequence to be replacedctxstring a mode such asinsert,normal.
Examples
aceVimMap('J', ':bn', 'normal');
addVimMapKey
Add map key in ACE editor.
Parameters
objectsobject multiple objects to define key map in ACE, see more from ace/keyboard/vim.js
Examples
addVimMapKey(
{
keys: 'n',
type: 'motion',
motion: 'moveByCharacters',
motionArgs: {
forward: false
}
},
{
keys: 'e',
type: 'motion',
motion: 'moveByLines',
motionArgs: {
forward: true,
linewise: true
}
}
);
getBrowserName
Get current browser name
Returns string "Chrome" | "Firefox" | "Safari"
Front.showBanner
Show message in banner.
Parameters
msgstring the message to be displayed in banner.timeoutnumber milliseconds after which the banner will disappear. (optional, default1600)
Examples
Front.showBanner(window.location.href);
Front.showPopup
Show message in popup.
Parameters
msgstring the message to be displayed in popup.
Examples
Front.showPopup(window.location.href);
isElementPartiallyInViewport
Check whether an element is in viewport.
Parameters
elElement the element to be checked.ignoreSizeboolean whether to ignore size of the element, otherwise the element must be with size 4*4. (optional, defaultfalse)
Returns boolean
getLargeElements
Get large elements that are currently visible in the viewport. A large element is defined as one that takes up a significant portion of the viewport.
Parameters
minWidthnumber Minimum width as a fraction of viewport width (0.0 to 1.0) (optional, default0.3)minHeightnumber Minimum height as a fraction of viewport height (0.0 to 1.0) (optional, default0.3)
Examples
// Get elements that are at least 30% of viewport dimensions
var largeElements = getLargeElements();
// Get elements that are at least 50% of viewport dimensions
var veryLargeElements = getLargeElements(0.5, 0.5);
Returns Array<Element> Array of large visible elements
getClickableElements
Get all clickable elements. SurfingKeys has its own logic to identify clickable elements, such as a HTMLAnchorElement or elements with cursor as pointer. This function provides two parameters to identify those clickable elements that SurfingKeys failed to identify.
Parameters
selectorStringstring extra css selector of those clickable elements.patternregex a regular expression that matches text of the clickable elements.
Examples
var elms = getClickableElements("[rel=link]", /click this/);
Returns array array of clickable elements.
tabOpenLink
Open links in new tabs.
Parameters
strstring links to be opened, the links should be split by\nif there are more than one.simultaneousnessnumber how many tabs will be opened simultaneously, the rest will be queued and opened later whenever a tab is closed. (optional, default5)
Examples
tabOpenLink('https://github.com/brookhong/Surfingkeys')