add more vim bindings

This commit is contained in:
Robert Burnett 2024-11-20 15:18:17 -06:00 committed by CJ van den Berg
parent ba82922ce9
commit ae91afe255
2 changed files with 94 additions and 8 deletions

View file

@ -3,6 +3,12 @@
"syntax": "vim",
"on_match_failure": "ignore",
"press": [
["b", "move_word_left"],
["w", "move_word_right_vim"],
["e", "move_word_right"],
["x", "delete_forward"],
["u", "undo"],
["j", "move_down"],
["k", "move_up"],
["l", "move_right_vim"],
@ -17,23 +23,78 @@
[";", "open_command_palette"],
["<S-;>", "open_command_palette"],
["p", "paste"],
["gd", "goto_definition"],
["gi", "goto_implementation"],
["gy", "goto_type_definition"],
["gg", "move_buffer_begin"],
["g<S-d>", "goto_declaration"],
["<S-g>", "move_buffer_end"],
["d<S-4>", "delete_to_end"],
["d4", "delete_to_end"],
["<C-u>", "cursor_half_page_up"],
["<C-d>", "cursor_half_page_down"]
["<C-e>", "open_recent"],
["<C-u>", "move_scroll_page_up"],
["<C-d>", "move_scroll_page_down"],
["<C-r>", "redo"],
["<C-o>", "jump_back"],
["<C-i>", "jump_forward"],
["<C-j>", "toggle_panel"],
["<C-z>", "undo"],
["<C-y>", "redo"],
["<C-q>", "quit"],
["<C-w>", "close_file"],
["<C-s>", "save_file"],
["<C-l>", "scroll_view_center_cycle"],
["<C-n>", "goto_next_match"],
["<C-p>", "goto_prev_match"],
["<C-b>", "move_to_char", false],
["<C-t>", "move_to_char", true],
["<C-x>", "cut"],
["<C-c>", "copy"],
["<C-v>", "system_paste"],
["<C-k>", "TODO"],
["<C-f>", "find"],
["<C-g>", "goto"],
["<C-a>", "select_all"],
["<C-/>", "toggle_comment"],
["<C-CR>", "smart_insert_line_after"],
["<C-Space","selections_reverse"],
["<C-End>","move_buffer_end"],
["<C-Home>", "move_buffer_begin"],
["<C-Up>", "move_scroll_up"],
["<C-Down>", "move_scroll_down"],
["<C-Left>", "move_word_left"],
["<C-Right>", "move_word_right"],
["<C-BS>", "delete_word_left"],
["<C-Del>", "delete_word_right"],
["<C-F5>", "toggle_inspector_view"],
["<C-F10>", "toggle_whitespace_mode"],
["<F2>", "toggle_input_mode"],
["<F3>", "goto_next_match"],
["<F15>", "goto_prev_match"],
["<F5>", "toggle_inspector_view"],
["<F6>", "dump_current_line_tree"],
["<F7>", "dump_current_line"],
["<F9>", "theme_prev"],
["<F10>", "theme_next"],
["<F11>", "toggle_panel"],
["<F12>", "goto_definition"],
["<F34>", "toggle_whitespace_mode"],
["<CR>", "smart_insert_line"],
["<Del>", "delete_forward"],
["<BS>", "delete_backward"]
]
},
"insert": {
"syntax": "vim",
"press": [
["jk", "enter_mode", "vim/normal"],
["<Esc>", "enter_mode", "vim/normal"]
["<Esc>", "enter_mode", "vim/normal"],
["<Del>", "delete_forward"],
["<BS>", "delete_backward"]
]
}
}

View file

@ -15,6 +15,7 @@ pub const ParseError = error{
InvalidStartOfControlBinding,
InvalidStartOfShiftBinding,
InvalidStartOfDelBinding,
InvalidStartOfEscBinding,
InvalidStartOfHomeBinding,
InvalidCRBinding,
InvalidSpaceBinding,
@ -117,7 +118,11 @@ pub fn parse_key_events(allocator: std.mem.Allocator, event: input.Event, str: [
'-' => {
state = .modifier;
},
else => return parse_error(error.InvalidStartOfControlBinding, "str: {s}, i: {} c: {c}", .{ str, i, str[i] }),
else => return parse_error(
error.InvalidStartOfControlBinding,
"str: {s}, i: {} c: {c}",
.{ str, i, str[i] },
),
}
},
'S' => {
@ -128,7 +133,11 @@ pub fn parse_key_events(allocator: std.mem.Allocator, event: input.Event, str: [
'p' => {
state = .space;
},
else => return parse_error(error.InvalidStartOfShiftBinding, "str: {s}, i: {} c: {c}", .{ str, i, str[i] }),
else => return parse_error(
error.InvalidStartOfShiftBinding,
"str: {s}, i: {} c: {c}",
.{ str, i, str[i] },
),
}
},
'F' => {
@ -154,7 +163,15 @@ pub fn parse_key_events(allocator: std.mem.Allocator, event: input.Event, str: [
state = .bs;
},
'E' => {
state = .esc;
state = switch (try peek(str, i)) {
's' => .esc,
'n' => .end,
else => return parse_error(
error.InvalidStartOfEscBinding,
"str: {s}, i: {} c: {c}",
.{ str, i, str[i] },
),
};
},
'D' => {
switch (try peek(str, i)) {
@ -167,13 +184,21 @@ pub fn parse_key_events(allocator: std.mem.Allocator, event: input.Event, str: [
'e' => {
state = .del;
},
else => return parse_error(error.InvalidStartOfDelBinding, "str: {s}, i: {} c: {c}", .{ str, i, str[i] }),
else => return parse_error(
error.InvalidStartOfDelBinding,
"str: {s}, i: {} c: {c}",
.{ str, i, str[i] },
),
}
},
'H' => {
state = .home;
},
else => return parse_error(error.InvalidStartOfHomeBinding, "str: {s}, i: {} c: {c}", .{ str, i, str[i] }),
else => return parse_error(
error.InvalidStartOfHomeBinding,
"str: {s}, i: {} c: {c}",
.{ str, i, str[i] },
),
}
},
.insert => {