aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-06-07 15:28:17 +0000
committerBlaž Hrastnik2020-06-07 15:28:17 +0000
commit843c20a5504a110dd0bc726d84062851290f1afe (patch)
tree164b2a39c9620cab0f8a3e2a6c14a71317939515 /helix-term/src
parente98cdebf1eb6ea5233c0d4cb0ae84c251fdae987 (diff)
Add a keymap module.
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/keymap.rs116
-rw-r--r--helix-term/src/main.rs3
2 files changed, 118 insertions, 1 deletions
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
new file mode 100644
index 00000000..b2d6738b
--- /dev/null
+++ b/helix-term/src/keymap.rs
@@ -0,0 +1,116 @@
+use crossterm::event::{KeyEvent as Key, KeyModifiers as Modifiers};
+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>;
+
+fn default() -> Keymap {
+ hashmap!(
+ Key {
+ code: "h",
+ modifiers: Modifiers::NONE
+ } => commands::move_char_left,
+ Key {
+ code: "j",
+ modifiers: Modifiers::NONE
+ } => commands::move_line_down,
+ Key {
+ code: "k",
+ modifiers: Modifiers::NONE
+ } => commands::move_line_up,
+ Key {
+ code: "l",
+ modifiers: Modifiers::NONE
+ } => commands::move_char_right,
+ );
+}
diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs
index 9a09e8c7..6a04bdb7 100644
--- a/helix-term/src/main.rs
+++ b/helix-term/src/main.rs
@@ -1,6 +1,7 @@
#![allow(unused)]
// mod editor;
-mod component;
+// mod component;
+mod keymap;
// use editor::Editor;