2020-06-07 19:31:11 +04:00
|
|
|
use crossterm::event::{KeyCode, KeyEvent as Key, KeyModifiers as Modifiers};
|
2020-06-07 19:28:17 +04:00
|
|
|
use helix_core::commands::{self, Command};
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
// Kakoune-inspired:
|
|
|
|
// mode = {
|
|
|
|
// normal = {
|
|
|
|
// q = record_macro
|
|
|
|
// w = (next) word
|
|
|
|
// e = end of word
|
|
|
|
// r =
|
|
|
|
// t = 'till char
|
|
|
|
// y = yank
|
|
|
|
// u = undo
|
|
|
|
// U = redo
|
|
|
|
// i = insert
|
|
|
|
// I = INSERT (start of line)
|
|
|
|
// o = open below (insert on new line below)
|
|
|
|
// O = open above (insert on new line above)
|
|
|
|
// p = paste (before cursor)
|
|
|
|
// P = PASTE (after cursor)
|
|
|
|
// ` =
|
|
|
|
// [ = select to text object start (alt = select whole object)
|
|
|
|
// ] = select to text object end
|
|
|
|
// { = extend to inner object start
|
|
|
|
// } = extend to inner object end
|
|
|
|
// a = append
|
|
|
|
// A = APPEND (end of line)
|
|
|
|
// s = split
|
|
|
|
// S = select
|
|
|
|
// d = delete()
|
|
|
|
// f = find_char()
|
|
|
|
// g = goto (gg, G, gc, gd, etc)
|
|
|
|
//
|
|
|
|
// h = move_char_left(n)
|
|
|
|
// j = move_line_down(n)
|
|
|
|
// k = move_line_up(n)
|
|
|
|
// l = move_char_right(n)
|
|
|
|
// : = command line
|
|
|
|
// ; = collapse selection to cursor
|
|
|
|
// " = use register
|
|
|
|
// ` = convert case? (to lower) (alt = swap case)
|
|
|
|
// ~ = convert to upper case
|
|
|
|
// . = repeat last command
|
|
|
|
// \ = disable hook?
|
|
|
|
// / = search
|
|
|
|
// > = indent
|
|
|
|
// < = deindent
|
|
|
|
// % = select whole buffer (in vim = jump to matching bracket)
|
|
|
|
// * = search pattern in selection
|
|
|
|
// ( = rotate main selection backward
|
|
|
|
// ) = rotate main selection forward
|
|
|
|
// - = trim selections? (alt = merge contiguous sel together)
|
|
|
|
// @ = convert tabs to spaces
|
|
|
|
// & = align cursor
|
|
|
|
// ? = extend to next given regex match (alt = to prev)
|
|
|
|
//
|
|
|
|
// z = save selections
|
|
|
|
// Z = restore selections
|
|
|
|
// x = select line
|
|
|
|
// X = extend line
|
|
|
|
// c = change selected text
|
|
|
|
// C = copy selection?
|
|
|
|
// v = view menu (viewport manipulation)
|
|
|
|
// b = select to previous word start
|
|
|
|
// B = select to previous WORD start
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// = = align?
|
|
|
|
// + =
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
macro_rules! hashmap {
|
|
|
|
(@single $($x:tt)*) => (());
|
|
|
|
(@count $($rest:expr),*) => (<[()]>::len(&[$(hashmap!(@single $rest)),*]));
|
|
|
|
|
|
|
|
($($key:expr => $value:expr,)+) => { hashmap!($($key => $value),+) };
|
|
|
|
($($key:expr => $value:expr),*) => {
|
|
|
|
{
|
|
|
|
let _cap = hashmap!(@count $($key),*);
|
|
|
|
let mut _map = ::std::collections::HashMap::with_capacity(_cap);
|
|
|
|
$(
|
|
|
|
let _ = _map.insert($key, $value);
|
|
|
|
)*
|
|
|
|
_map
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
type Keymap = HashMap<Key, Command>;
|
|
|
|
|
2020-06-16 13:00:34 +04:00
|
|
|
pub fn default() -> Keymap {
|
2020-06-07 19:28:17 +04:00
|
|
|
hashmap!(
|
|
|
|
Key {
|
2020-06-07 19:31:11 +04:00
|
|
|
code: KeyCode::Char('h'),
|
2020-06-07 19:28:17 +04:00
|
|
|
modifiers: Modifiers::NONE
|
2020-06-07 19:31:11 +04:00
|
|
|
} => commands::move_char_left as Command,
|
2020-06-07 19:28:17 +04:00
|
|
|
Key {
|
2020-06-07 19:31:11 +04:00
|
|
|
code: KeyCode::Char('j'),
|
2020-06-07 19:28:17 +04:00
|
|
|
modifiers: Modifiers::NONE
|
2020-06-07 19:31:11 +04:00
|
|
|
} => commands::move_line_down as Command,
|
2020-06-07 19:28:17 +04:00
|
|
|
Key {
|
2020-06-07 19:31:11 +04:00
|
|
|
code: KeyCode::Char('k'),
|
2020-06-07 19:28:17 +04:00
|
|
|
modifiers: Modifiers::NONE
|
2020-06-07 19:31:11 +04:00
|
|
|
} => commands::move_line_up as Command,
|
2020-06-07 19:28:17 +04:00
|
|
|
Key {
|
2020-06-07 19:31:11 +04:00
|
|
|
code: KeyCode::Char('l'),
|
2020-06-07 19:28:17 +04:00
|
|
|
modifiers: Modifiers::NONE
|
2020-06-07 19:31:11 +04:00
|
|
|
} => commands::move_char_right as Command,
|
|
|
|
)
|
2020-06-07 19:28:17 +04:00
|
|
|
}
|