feat(vim): Add word movement for visual mode, and complete vim mode cut to end of line

This commit is contained in:
lulvz 2025-02-12 21:38:27 +00:00
parent 4e4034d0f2
commit e443e8397b
2 changed files with 36 additions and 9 deletions

View file

@ -56,15 +56,15 @@
["gD", "goto_declaration"], ["gD", "goto_declaration"],
["G", "move_buffer_end"], ["G", "move_buffer_end"],
["d$", "delete_to_end"], ["d$", "cut_to_end_vim"],
["dw", "cut_word_right_vim"], ["dw", "cut_word_right_vim"],
["db", "cut_word_left_vim"], ["db", "cut_word_left_vim"],
["dd", "cut_internal_vim"], ["dd", "cut_internal_vim"],
["\"_dd", "delete_line"], ["\"_dd", "delete_line"],
["cc", ["cut_internal_vim"], ["enter_mode", "insert"]], ["cc", ["cut_internal_vim"], ["enter_mode", "insert"]],
["C", ["delete_to_end"], ["enter_mode", "insert"]], ["C", ["cut_to_end_vim"], ["enter_mode", "insert"]],
["D", "delete_to_end"], ["D", "cut_to_end_vim"],
["cw", ["cut_word_right_vim"], ["enter_mode", "insert"]], ["cw", ["cut_word_right_vim"], ["enter_mode", "insert"]],
["cb", ["cut_word_left_vim"], ["enter_mode", "insert"]], ["cb", ["cut_word_left_vim"], ["enter_mode", "insert"]],
@ -103,6 +103,12 @@
["h", "select_left"], ["h", "select_left"],
["l", "select_right"], ["l", "select_right"],
["b", "select_word_left_vim"],
["w", "select_word_right_vim"],
["W", "select_word_right"],
["B", "select_word_left"],
["e", "select_word_right_end_vim"],
["0", "move_begin"], ["0", "move_begin"],
["^", "smart_move_begin"], ["^", "smart_move_begin"],
["$", "move_end"], ["$", "move_end"],
@ -124,8 +130,8 @@
["s", ["cut_forward_internal"], ["cancel"], ["enter_mode", "insert"]], ["s", ["cut_forward_internal"], ["cancel"], ["enter_mode", "insert"]],
["c", ["cut_forward_internal"], ["cancel"], ["enter_mode", "insert"]], ["c", ["cut_forward_internal"], ["cancel"], ["enter_mode", "insert"]],
["C", ["delete_to_end"], ["enter_mode", "insert"]], ["C", ["cut_to_end_vim"], ["enter_mode", "insert"]],
["D", "delete_to_end"] ["D", "cut_to_end_vim"]
] ]
}, },
"visual line": { "visual line": {
@ -160,8 +166,8 @@
["s", ["cut_internal_vim"], ["cancel"], ["enter_mode", "insert"]], ["s", ["cut_internal_vim"], ["cancel"], ["enter_mode", "insert"]],
["c", ["cut_forward_internal"], ["cancel"], ["enter_mode", "insert"]], ["c", ["cut_forward_internal"], ["cancel"], ["enter_mode", "insert"]],
["C", ["delete_to_end"], ["enter_mode", "insert"]], ["C", ["cut_to_end_vim"], ["enter_mode", "insert"]],
["D", "delete_to_end"] ["D", "cut_to_end_vim"]
] ]
}, },
"insert": { "insert": {
@ -170,8 +176,8 @@
"line_numbers": "absolute", "line_numbers": "absolute",
"cursor": "beam", "cursor": "beam",
"press": [ "press": [
["jk", "enter_mode", "normal"],
["<Esc>", "enter_mode", "normal"], ["<Esc>", ["move_left_vim"], ["enter_mode", "normal"]],
["<Del>", "delete_forward"], ["<Del>", "delete_forward"],
["<BS>", "delete_backward"], ["<BS>", "delete_backward"],
["<CR>", "smart_insert_line"], ["<CR>", "smart_insert_line"],

View file

@ -3536,6 +3536,13 @@ pub const Editor = struct {
} }
pub const select_word_left_meta = .{ .description = "Select left by word" }; pub const select_word_left_meta = .{ .description = "Select left by word" };
pub fn select_word_left_vim(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_word_left_vim);
self.clamp();
}
pub const select_word_left_vim_meta = .{ .description = "Select left by word (vim)" };
pub fn select_word_right(self: *Self, _: Context) Result { pub fn select_word_right(self: *Self, _: Context) Result {
const root = try self.buf_root(); const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_word_right); try self.with_selections_const(root, move_cursor_word_right);
@ -3543,6 +3550,20 @@ pub const Editor = struct {
} }
pub const select_word_right_meta = .{ .description = "Select right by word" }; pub const select_word_right_meta = .{ .description = "Select right by word" };
pub fn select_word_right_vim(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_word_right_vim);
self.clamp();
}
pub const select_word_right_vim_meta = .{ .description = "Select right by word (vim)" };
pub fn select_word_right_end_vim(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_word_right_end_vim);
self.clamp();
}
pub const select_word_right_end_vim_meta = .{ .description = "Select right by end of word (vim)" };
pub fn select_word_begin(self: *Self, _: Context) Result { pub fn select_word_begin(self: *Self, _: Context) Result {
const root = try self.buf_root(); const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_word_begin); try self.with_selections_const(root, move_cursor_word_begin);