start porting over helix keybindings

some are completly wrong many have comments about
what the proper helix command looks like,
only touches normal mode
This commit is contained in:
gabydd 2024-08-27 00:08:38 -04:00 committed by CJ van den Berg
parent 7b877de6d7
commit 7dbb5458f5

View file

@ -91,114 +91,59 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
'E' => self.cmd("open_recent", .{}),
'U' => self.cmd("move_scroll_page_up", .{}),
'D' => self.cmd("move_scroll_page_down", .{}),
'R' => self.cmd("redo", .{}),
'O' => self.cmd("jump_back", .{}),
'I' => self.cmd("jump_forward", .{}),
'J' => self.cmd("toggle_panel", .{}),
'Z' => self.cmd("undo", .{}),
'Y' => self.cmd("redo", .{}),
'Q' => self.cmd("quit", .{}),
'W' => self.cmd("close_file", .{}),
'S' => self.cmd("save_file", .{}),
'L' => self.cmd_cycle3("scroll_view_center", "scroll_view_top", "scroll_view_bottom", .{}),
'N' => self.cmd("goto_next_match", .{}),
'P' => self.cmd("goto_prev_match", .{}),
'B' => self.cmd("move_to_char", command.fmt(.{false})),
'T' => self.cmd("move_to_char", command.fmt(.{true})),
'X' => self.cmd("cut", .{}),
'C' => self.cmd("copy", .{}),
'V' => self.cmd("system_paste", .{}),
'K' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers },
'F' => self.cmd("find", .{}),
'G' => self.cmd("goto", .{}),
'A' => self.cmd("select_all", .{}),
'/' => self.cmd("toggle_comment", .{}),
key.ENTER => self.cmd("smart_insert_line_after", .{}),
key.SPACE => self.cmd("selections_reverse", .{}),
key.END => self.cmd("move_buffer_end", .{}),
key.HOME => self.cmd("move_buffer_begin", .{}),
key.UP => self.cmd("move_scroll_up", .{}),
key.DOWN => self.cmd("move_scroll_down", .{}),
key.PGUP => self.cmd("move_scroll_page_up", .{}),
key.PGDOWN => self.cmd("move_scroll_page_down", .{}),
key.LEFT => self.cmd("move_word_left", .{}),
key.RIGHT => self.cmd("move_word_right", .{}),
key.BACKSPACE => self.cmd("delete_word_left", .{}),
key.DEL => self.cmd("delete_word_right", .{}),
key.F05 => self.cmd("toggle_inspector_view", .{}),
key.F10 => self.cmd("toggle_whitespace", .{}), // aka F34
else => {},
},
mod.CTRL | mod.SHIFT => switch (keynormal) {
'P' => self.cmd("open_command_palette", .{}),
'D' => self.cmd("dupe_down", .{}),
'Z' => self.cmd("redo", .{}),
'Q' => self.cmd("quit_without_saving", .{}),
'W' => self.cmd("close_file_without_saving", .{}),
'F' => self.cmd("find_in_files", .{}),
'L' => self.cmd_async("add_cursor_all_matches"),
'I' => self.cmd_async("toggle_inspector_view"),
key.ENTER => self.cmd("smart_insert_line_before", .{}),
key.END => self.cmd("select_buffer_end", .{}),
key.HOME => self.cmd("select_buffer_begin", .{}),
key.UP => self.cmd("select_scroll_up", .{}),
key.DOWN => self.cmd("select_scroll_down", .{}),
key.LEFT => self.cmd("select_word_left", .{}),
key.RIGHT => self.cmd("select_word_right", .{}),
'W' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers },
'c' => self.cmd("toggle_comment", .{}),
else => {},
},
mod.ALT => switch (keynormal) {
'J' => self.cmd("join_next_line", .{}),
'N' => self.cmd("goto_next_match", .{}),
'P' => self.cmd("goto_prev_match", .{}),
'U' => self.cmd("to_upper", .{}),
'L' => self.cmd("to_lower", .{}),
'I' => self.cmd("toggle_inputview", .{}),
'B' => self.cmd("move_word_left", .{}),
'F' => self.cmd("move_word_right", .{}),
'S' => self.cmd("filter", command.fmt(.{"sort"})),
'V' => self.cmd("paste", .{}),
key.LEFT => self.cmd("jump_back", .{}),
key.RIGHT => self.cmd("jump_forward", .{}),
'N' => self.cmd("pull_back", .{}), // next sibling
'`' => self.cmd("to_upper", .{}),
'd' => self.cmd("delete_backward", .{}),
'c' => {
try self.cmd("delete_backward", .{});
try self.cmd("enter_mode", command.fmt(.{"helix/insert"}));
},
's' => self.cmd("toggle_inputview", .{}),
'-' => self.cmd("move_word_left", .{}),
'_' => self.cmd("move_word_right", .{}),
';' => self.cmd("filter", command.fmt(.{"sort"})),
'O' => self.cmd("pull_up", .{}),
key.UP => self.cmd("pull_up", .{}),
'P' => self.cmd("pull_left", .{}),
key.RIGHT => self.cmd("jump_forward", .{}),
'I' => self.cmd("jump_back", .{}),
key.DOWN => self.cmd("pull_down", .{}),
key.ENTER => self.cmd("insert_line", .{}),
key.F10 => self.cmd("gutter_mode_next", .{}), // aka F58
else => {},
},
mod.ALT | mod.SHIFT => switch (keynormal) {
'P' => self.cmd("open_command_palette", .{}),
'D' => self.cmd("dupe_up", .{}),
'F' => self.cmd("filter", command.fmt(.{ "zig", "fmt", "--stdin" })),
'S' => self.cmd("filter", command.fmt(.{ "sort", "-u" })),
'V' => self.cmd("paste", .{}),
'I' => self.cmd("add_cursors_to_line_ends", .{}),
key.LEFT => self.cmd("move_scroll_left", .{}),
key.RIGHT => self.cmd("move_scroll_right", .{}),
key.UP => self.cmd("add_cursor_up", .{}),
key.DOWN => self.cmd("add_cursor_down", .{}),
'C' => self.cmd("select_up", .{}),
'I' => self.cmd("dupe_up", .{}), // select all children
key.DOWN => self.cmd("dupe_up", .{}), // select all children
else => {},
},
mod.SHIFT => switch (keypress) {
key.F03 => self.cmd("goto_prev_match", .{}),
key.LEFT => self.cmd("select_left", .{}),
key.RIGHT => self.cmd("select_right", .{}),
key.UP => self.cmd("select_up", .{}),
key.DOWN => self.cmd("select_down", .{}),
key.HOME => self.cmd("smart_select_begin", .{}),
key.END => self.cmd("select_end", .{}),
key.PGUP => self.cmd("select_page_up", .{}),
key.PGDOWN => self.cmd("select_page_down", .{}),
key.ENTER => self.cmd("smart_insert_line_before", .{}),
key.BACKSPACE => self.cmd("delete_backward", .{}),
'r' => self.cmd("goto_prev_match", .{}), // replace with yanked
key.TAB => self.cmd("unindent", .{}),
';' => self.cmd("open_command_palette", .{}),
'n' => self.cmd("goto_prev_match", .{}),
'a' => self.seq(.{ "move_end", "enter_mode" }, command.fmt(.{"helix/insert"})),
'i' => self.seq(.{ "smart_move_begin", "enter_mode" }, command.fmt(.{"helix/insert"})),
'4' => self.cmd("move_end", .{}),
'w' => self.cmd("select_word_right", .{}), // move long word next
'b' => self.cmd("select_word_left", .{}), // move long word prev
'e' => self.cmd("select_word_end", .{}), // move long word end
'c' => self.cmd("select_down", .{}), // copy_selection_on_next_line
's' => self.cmd("select_down", .{}), // split_selection
'5' => self.cmd("select_all", .{}),
'x' => self.cmd("extend", .{}), // extend_to_line_bounds
'p' => self.cmd("paste", .{}), // paste_before
'u' => self.cmd("undo", .{}),
'g' => if (self.count == 0)
self.cmd("move_buffer_end", .{})
else {
@ -214,44 +159,35 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
else => {},
},
0 => switch (keypress) {
key.F02 => self.cmd("toggle_input_mode", .{}),
key.F03 => self.cmd("goto_next_match", .{}),
key.F15 => self.cmd("goto_prev_match", .{}), // S-F3
key.F05 => self.cmd("toggle_inspector_view", .{}), // C-F5
key.F06 => self.cmd("dump_current_line_tree", .{}),
key.F07 => self.cmd("dump_current_line", .{}),
key.F09 => self.cmd("theme_prev", .{}),
key.F10 => self.cmd("theme_next", .{}),
key.F11 => self.cmd("toggle_panel", .{}),
key.F12 => self.cmd("goto_definition", .{}),
key.F34 => self.cmd("toggle_whitespace", .{}), // C-F10
key.F58 => self.cmd("gutter_mode_next", .{}), // A-F10
key.ESC => self.cmd("cancel", .{}),
key.ENTER => self.cmd("smart_insert_line", .{}),
key.DEL => self.cmd("delete_forward", .{}),
key.BACKSPACE => self.cmd("delete_backward", .{}),
':' => self.cmd("open_command_palette", .{}),
'%' => self.cmd("select_all", .{}),
'i' => self.cmd("enter_mode", command.fmt(.{"helix/insert"})),
'a' => self.seq(.{ "move_right", "enter_mode" }, command.fmt(.{"helix/insert"})),
'v' => self.cmd("enter_mode", command.fmt(.{"helix/visual"})),
'v' => self.cmd("enter_mode", command.fmt(.{"helix/select"})),
'/' => self.cmd("find", .{}),
'n' => self.cmd("goto_next_match", .{}),
'h' => self.cmd_count("move_left_vim", .{}),
'h' => self.cmd_count("move_left", .{}),
'j' => self.cmd_count("move_down", .{}),
'k' => self.cmd_count("move_up", .{}),
'l' => self.cmd_count("move_right_vim", .{}),
' ' => self.cmd_count("move_right_vim", .{}),
'l' => self.cmd_count("move_right", .{}),
'b' => self.cmd_count("move_word_left", .{}),
'w' => self.cmd_count("move_word_right_vim", .{}),
'e' => self.cmd_count("move_word_right", .{}),
'$' => self.cmd_count("move_end", .{}),
'0' => self.cmd_count("move_begin", .{}),
'b' => self.cmd_count("select_word_left", .{}),
'w' => self.cmd_count("select_word_right", .{}),
'e' => self.cmd_count("select_word_end", .{}),
'd' => self.cmd("cut", .{}),
'c' => {
try self.cmd("cut", .{});
try self.cmd("enter_mode", command.fmt(.{"helix/insert"}));
},
's' => self.cmd("select", .{}), // select regex
';' => self.cmd("collapse_cursors", .{}),
'*' => self.cmd("find_selection_match", .{}),
'1' => self.add_count(1),
'2' => self.add_count(2),
'3' => self.add_count(3),
@ -262,21 +198,26 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
'8' => self.add_count(8),
'9' => self.add_count(9),
'x' => self.cmd_count("delete_forward", .{}),
'x' => self.cmd_count("select_line_at_cursor", .{}),
'u' => self.cmd("undo", .{}),
'd' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers },
'm' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers },
'r' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers },
'c' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers },
'[' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers },
']' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers },
'z' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers },
' ' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers },
'g' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers },
'y' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers },
'>' => self.cmd("indent", .{}),
'<' => self.cmd("unindent", .{}),
',' => self.cmd("cancel", .{}),
'p' => self.cmd("paste", .{}),
'y' => self.cmd("yank", .{}),
'o' => self.seq(.{ "smart_insert_line_after", "enter_mode" }, command.fmt(.{"helix/insert"})),
key.LEFT => self.cmd("move_left_vim", .{}),
key.RIGHT => self.cmd("move_right_vim", .{}),
key.LEFT => self.cmd("move_left", .{}),
key.RIGHT => self.cmd("move_right", .{}),
key.UP => self.cmd("move_up", .{}),
key.DOWN => self.cmd("move_down", .{}),
key.HOME => self.cmd("smart_move_begin", .{}),
@ -290,7 +231,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
};
}
fn mapFollower(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
fn mapFollower(self: *Self, keypress: u32, _: u32, modifiers: u32) !void {
if (keypress == key.LCTRL or
keypress == key.RCTRL or
keypress == key.LALT or
@ -303,70 +244,39 @@ fn mapFollower(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
defer self.leader = null;
const ldr = if (self.leader) |leader| leader else return;
return switch (ldr.modifiers) {
mod.CTRL => switch (ldr.keypress) {
'K' => switch (modifiers) {
mod.CTRL => switch (keypress) {
'U' => self.cmd("delete_to_begin", .{}),
'K' => self.cmd("delete_to_end", .{}),
'D' => self.cmd("move_cursor_next_match", .{}),
'T' => self.cmd("change_theme", .{}),
else => {},
},
else => {},
},
else => {},
},
0 => switch (ldr.keypress) {
'C' => {
'm' => {
// apparently not a thing
},
'[' => {
try switch (modifiers) {
mod.SHIFT => switch (egc) {
'$' => self.cmd("delete_to_end", .{}),
else => {},
},
0 => switch (keypress) {
'W', 'E' => self.seq_count(.{ "select_word_right", "cut" }, .{}),
'd' => self.cmd("goto_next_diagnostic", .{}),
'D' => self.cmd("goto_next_diagnostic", .{}), // goto last diagnostic
else => {},
},
else => switch (egc) {
'$' => self.cmd("delete_to_end", .{}),
else => {},
},
};
if (ldr.keypress == 'C')
try self.cmd("enter_mode", command.fmt(.{"helix/insert"}));
},
'D' => {
']' => {
try switch (modifiers) {
mod.SHIFT => switch (egc) {
'$' => self.cmd("delete_to_end", .{}),
else => {},
},
0 => switch (keypress) {
'D' => self.seq_count(.{ "move_begin", "select_end", "select_right", "cut" }, .{}),
'W' => self.seq_count(.{ "select_word_right", "select_word_right", "select_word_left", "cut" }, .{}),
'E' => self.seq_count(.{ "select_word_right", "cut" }, .{}),
'd' => self.cmd("goto_prev_diagnostic", .{}),
'D' => self.cmd("goto_prev_diagnostic", .{}), // goto first diagnostic
else => {},
},
else => switch (egc) {
'$' => self.cmd("delete_to_end", .{}),
else => {},
},
};
if (ldr.keypress == 'C')
try self.cmd("enter_mode", command.fmt(.{"helix/insert"}));
},
'R' => switch (modifiers) {
mod.SHIFT, 0 => if (!key.synthesized_p(keypress)) {
var count = self.count;
try self.cmd_count("delete_forward", .{});
while (count > 0) : (count -= 1)
try self.insert_code_point(egc);
},
else => {},
},
'Z' => switch (modifiers) {
' ' => switch (modifiers) {
0 => switch (keypress) {
'Z' => self.cmd_cycle3("scroll_view_center", "scroll_view_top", "scroll_view_bottom", .{}),
'F' => self.cmd("open_file", .{}),
'B' => self.cmd("open_buffer", .{}),
'Y' => self.cmd("yank", .{}),
'P' => self.cmd("paste", .{}),
'/' => self.cmd("find", .{}),
'K' => self.cmd("hover", .{}),
'C' => self.cmd("toggle_comment", .{}),
else => {},
},
else => {},
@ -374,6 +284,7 @@ fn mapFollower(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
'G' => switch (modifiers) {
0 => switch (keypress) {
'G' => self.cmd("move_buffer_begin", .{}),
'E' => self.cmd("move_buffer_end", .{}),
'D' => self.cmd("goto_definition", .{}),
'I' => self.cmd("goto_implementation", .{}),
'Y' => self.cmd("goto_type_definition", .{}),
@ -385,26 +296,15 @@ fn mapFollower(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
},
else => {},
},
'Y' => {
try switch (modifiers) {
'w' => switch (modifiers) {
mod.SHIFT => switch (keypress) {
'4' => self.seq(.{ "select_to_end", "copy" }, .{}),
else => {},
},
0 => switch (keypress) {
'Y' => self.seq_count(.{ "move_begin", "select_end", "select_right", "copy" }, .{}),
'W' => self.seq_count(.{ "select_word_right", "select_word_right", "select_word_left", "copy" }, .{}),
'E' => self.seq_count(.{ "select_word_right", "copy" }, .{}),
else => {},
},
else => switch (egc) {
'$' => self.seq(.{ "select_to_end", "copy" }, .{}),
else => {},
},
};
if (ldr.keypress == 'C')
try self.cmd("enter_mode", command.fmt(.{"helix/insert"}));
},
else => {},
},
else => {},
@ -640,6 +540,10 @@ const cmds_ = struct {
try self.cmd("quit", .{});
}
pub fn o(self: *Self, _: Ctx) Result {
try self.cmd("open_file", .{});
}
pub fn @"wq!"(self: *Self, _: Ctx) Result {
self.cmd("save_file", .{}) catch {};
try self.cmd("quit_without_saving", .{});