From ae91afe255d9b0a6f21c19e1c832682f4a0a6dbf Mon Sep 17 00:00:00 2001 From: Robert Burnett Date: Wed, 20 Nov 2024 15:18:17 -0600 Subject: [PATCH] add more vim bindings --- src/keybind/builtin/vim.json | 67 ++++++++++++++++++++++++++++++++++-- src/keybind/parse_vim.zig | 35 ++++++++++++++++--- 2 files changed, 94 insertions(+), 8 deletions(-) diff --git a/src/keybind/builtin/vim.json b/src/keybind/builtin/vim.json index 714967e..cf481e8 100644 --- a/src/keybind/builtin/vim.json +++ b/src/keybind/builtin/vim.json @@ -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"], ["", "open_command_palette"], ["p", "paste"], + ["gd", "goto_definition"], ["gi", "goto_implementation"], ["gy", "goto_type_definition"], ["gg", "move_buffer_begin"], ["g", "goto_declaration"], ["", "move_buffer_end"], + ["d", "delete_to_end"], ["d4", "delete_to_end"], - ["", "cursor_half_page_up"], - ["", "cursor_half_page_down"] + + ["", "open_recent"], + ["", "move_scroll_page_up"], + ["", "move_scroll_page_down"], + ["", "redo"], + ["", "jump_back"], + ["", "jump_forward"], + ["", "toggle_panel"], + ["", "undo"], + ["", "redo"], + ["", "quit"], + ["", "close_file"], + ["", "save_file"], + ["", "scroll_view_center_cycle"], + ["", "goto_next_match"], + ["", "goto_prev_match"], + ["", "move_to_char", false], + ["", "move_to_char", true], + ["", "cut"], + ["", "copy"], + ["", "system_paste"], + ["", "TODO"], + ["", "find"], + ["", "goto"], + ["", "select_all"], + ["", "toggle_comment"], + ["", "smart_insert_line_after"], + ["","move_buffer_end"], + ["", "move_buffer_begin"], + ["", "move_scroll_up"], + ["", "move_scroll_down"], + ["", "move_word_left"], + ["", "move_word_right"], + ["", "delete_word_left"], + ["", "delete_word_right"], + ["", "toggle_inspector_view"], + ["", "toggle_whitespace_mode"], + + ["", "toggle_input_mode"], + ["", "goto_next_match"], + ["", "goto_prev_match"], + ["", "toggle_inspector_view"], + ["", "dump_current_line_tree"], + ["", "dump_current_line"], + ["", "theme_prev"], + ["", "theme_next"], + ["", "toggle_panel"], + ["", "goto_definition"], + ["", "toggle_whitespace_mode"], + ["", "smart_insert_line"], + ["", "delete_forward"], + ["", "delete_backward"] ] }, "insert": { "syntax": "vim", "press": [ ["jk", "enter_mode", "vim/normal"], - ["", "enter_mode", "vim/normal"] + ["", "enter_mode", "vim/normal"], + ["", "delete_forward"], + ["", "delete_backward"] ] } } diff --git a/src/keybind/parse_vim.zig b/src/keybind/parse_vim.zig index 99f85d4..d8845f9 100644 --- a/src/keybind/parse_vim.zig +++ b/src/keybind/parse_vim.zig @@ -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 => {