Skip to content

Instantly share code, notes, and snippets.

@sarkian
Created August 20, 2014 23:38
Show Gist options
  • Save sarkian/2673defa166c634a4500 to your computer and use it in GitHub Desktop.
Save sarkian/2673defa166c634a4500 to your computer and use it in GitHub Desktop.
Userscript for dwb browser that adds vim-like shortcuts in insert mode
//!javascript
function dispatchEvents(events, command, cm) {
var mode = util.getMode();
if(mode == Modes.InsertMode || (cm && mode == Modes.CommandMode))
events.forEach(function(e) {
util.dispatchEvent(e);
});
else if(command)
execute(command);
}
function keypress(val, ctrl) {
var e = {type: 8, keyVal: val};
if(ctrl)
e.state = Modifier.Control;
return e;
}
bind("Control h", dispatchEvents.bind(null, [keypress(0xff08)], "tabprev"), OverrideKey.insertMode); // <Backspace>
bind("Control w", dispatchEvents.bind(null, [keypress(0xff08, true)]), OverrideKey.insertMode); // <C-Backspace>
bind("Control u", dispatchEvents.bind(null, [keypress(0x61, true), keypress(0xff08)]), OverrideKey.insertMode); // <C-a><Backspace>
bind("Control e", dispatchEvents.bind(null, [keypress(0xff51)], null, true), OverrideKey.insertMode|OverrideKey.entryFocus); // <Left>
bind("Control l", dispatchEvents.bind(null, [keypress(0xff53)], "tabnext", true), OverrideKey.insertMode|OverrideKey.entryFocus); // <Right>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment