Skip to content
David Arnold edited this page Feb 20, 2024 · 25 revisions

Somewhat outdated keymap (KLE):

preview

We are still thinking about visual mode and there are some issues with kakoune and vim that we want to address.

vim

  • we think a visual first is better (multi-cursors support)

kakoune

  • we don't want to hold shift for extend
  • we don't want to use alt

both

  • we don't want to hold ctrl-f to page down (should be like in V kakoune as pager)
  • keep visual, linewise visual, visual block mode in vim while having the ability to be visual first
  • we prefer not to hold keys (shift, ctrl, alt)

Cases below may not be able to utilize lsp functions. Should be real cases for normal workflow. Commenting functions also won't be useful.

We want to provide one way without using count and one way using count since we may not always use count. Keystrokes count, pressing shift is considered a count.

Note

From vision.md:

  • Modal. Vim is a great idea.
  • Selection -> Action, not Verb -> Object. Interaction models aren't linguistics, and "selection first" lets you see what you're doing (among other benefits).
  • We aren't playing code golf. It's more important for the keymap to be consistent and easy to memorize than it is to save a key stroke or two when editing.

Start holding down a mod key (shift, ctrl, alt) is count as a keypress. Therefore we don't need a key combo that have the same keypress and do the same things as an existing key sequence, we only use a key combo for repeatable action.

E.g
Example Keypress
a 1
A 2
ab 2
AA = shift downaa[shift release] 3

Sample one

/// ```
/// impl EditorView {
///     pub fn new() -> Self {
///         Self {
///             keymap: keymap::default(),
///             on_next_key: None,
///             last_insert: (commands::normal_mode, Vec::new()),
///             completion: None,
///         }
///     }
/// ```

Case one

Delete the whole line starting from Self { to } (including last newline), cursor starts at /// (#) on line Self {.

vim

  • @pickfire V%d (5), with count 6dd (3)
  • @CBenoit V%d is (4) not (5)

kakoune

  • @pickfire ghMLd (6), with count 6Xd (4)
  • @vbauerster m<a-x>d (4)

helix

  • @pickfire Vmvld (6) if we follow vim, with count (current) ghV5jgld (9), with count (current + X) ghV5Xd (8)
  • @CBenoit with helix line-wise extend mode (like in vim), we should get Vmd (4) without count and V5jd (5) with count.

Case two

Add line comment before Self { to matching } all on same column, starting at Self {.

vim

  • @pickfire ctrl-vI// (7)

kakoune

  • @pickfire CCCCCi// (10) - I wish there is a better way, with count 5Ci// (7)
  • @vbauerster m<a-s>ghi//

helix

  • @pickfire maybe we need to have visual block?

Err, maybe we should count escape key?

  • TODO swapping key value position in code
  • TODO xml editing, joining child, removing parent, splitting child, swapping key position
  • TODO (rare use cases) drawing boxes
  • TODO I noticed that helix requires a lot more keys just to change till end of line (not including newline)

Reference:


Suggestions

These are some keys which can be re-mapped without clashes with other commands.

Normal Mode

nums: `1 2 3 4 5 6 7 8 9 0`
arrow: `left right up down`
KEYS: All captial alphabet keys
KEYS*: All KEYS other than U, K and C
Keys Keys
H M
@ C-~
# C-nums
^ C--
- C-=
+ C-q
\ C-e
. C-r
D C-t
L C-y
V C-p
C-j C-[
C-k C-]
C-l C-\
C-; C-{
C-' C-}
C-: C-|
C-" C-g
C-v C-h
C-. C-n
C-/ C-m
C-< C->
C-/ C-KEYS
C-? C-!
C-@ C-^
C-# C-&
C-$ C-*
C-% C-(
C-) C-_
C-+ C-arrow
A-- A-nums
A-= A-\
A-_ A-a
A-+ A-KEYS*
A-~ A-f
A-q A-g
A-w A-h
A-e A-j
A-r A-k
A-t A-l
A-y A-'
A-u A-"
A-[ A-z
A-] A-v
A-m A-@
A-/ A-#
A-< A-$
A-> A-%
A-? A-\
A-{ A-}
A-^ A-*
A-& S-arrow

Nix / Home Manager snippet

This snippet was designed to transparently honor the changes from normal mode to select mode when you have rebound a lot of things:

(I disabled a lot of keys with no_op to essentially redo the entire layout. This mapping helped me "align" the selection mode.)

{
    keys = let
      normal = importTOML ./keys.normal.toml;
      mapping_table = {
        # searching for all command having a correspondence with extend_ prefix
        # https://github.com/helix-editor/helix/blob/master/helix-term/src/commands.rs
        # see also: https://docs.helix-editor.com/keymap.html#select--extend-mode
        # > Select mode echoes Normal mode, but changes any movements to extend
        # > selections rather than replace them. Goto motions are also changed to extend [...]
        # goto commands seems to have a different handling
        "move_char_left" = "extend_char_left";
        "move_char_right" = "extend_char_right";
        "move_line_down" = "extend_line_down";
        "move_line_up" = "extend_line_up";
        "move_visual_line_down" = "extend_line_down";
        "move_visual_line_up" = "extend_line_up";
        "move_prev_word_start" = "extend_prev_word_start";
        "move_next_word_end" = "extend_next_word_end";
        "move_prev_long_word_start" = "extend_prev_long_word_start";
        "move_next_long_word_end" = "extend_next_long_word_end";
        "move_parent_node_start" = "extend_parent_node_start";
        "move_parent_node_end" = "extend_parent_node_end";
        "find_till_char" = "extend_till_char";
        "find_next_char" = "extend_next_char";
        "till_prev_char" = "extend_till_prev_char";
        "find_prev_char" = "extend_prev_char";
        "search_next" = "extend_search_prev";
        "search_prev" = "extend_search_prev";
      };
    in {
      inherit normal;
      select =
        mapAttrs (_: v: mapping_table.${v} or v) normal
        // {
          # rebound select mode key in normal mode -> override "append" in select mode
          "a" = "no_op";
          "C-a" = "no_op";
        };
    };
}