diff --git a/src/buf/buf_helpers.c b/src/buf/buf_helpers.c index 905cb67..07e42fb 100644 --- a/src/buf/buf_helpers.c +++ b/src/buf/buf_helpers.c @@ -769,8 +769,22 @@ void buf_change_line(void) { return; buf_change_selection(&sel); + win->cursor.x = 0; } +void buf_change_to_line_end(void) { + Buffer *buf = buf_cur(); + Window *win = window_cur(); + if (!PTR_VALID(buf) || !PTR_VALID(win)) + return; + + TextSelection sel; + if (!textobj_to_line_end(buf, win->cursor.y, win->cursor.x, &sel)) + return; + + buf_change_selection(&sel); + win->cursor.x = sel.start.col; +} void buf_move_cursor_key(int key) { BUFWIN(buf, win); diff --git a/src/buf/buf_helpers.h b/src/buf/buf_helpers.h index 83de9b3..2260108 100644 Binary files a/src/buf/buf_helpers.h and b/src/buf/buf_helpers.h differ diff --git a/src/commands/cmd_misc.c b/src/commands/cmd_misc.c index 17da287..2f67164 100644 --- a/src/commands/cmd_misc.c +++ b/src/commands/cmd_misc.c @@ -573,6 +573,7 @@ void cmd_new_line_above(const char *args) { win->cursor.x = 0; buf_insert_newline_in(buf); + win->cursor.y--; /* Cursor should now be on the new blank line above */ ed_set_mode(MODE_INSERT); } diff --git a/src/config.c b/src/config.c index 6857b4f..01911ca 100644 --- a/src/config.c +++ b/src/config.c @@ -81,6 +81,11 @@ void normal_mode_bindings() { cmapn(".", "repeat"); cmapn("q", "record"); cmapn("@", "play"); + cmapn("ZQ", "q!"); + cmapn("ZZ", "wq"); // not quite the same as in neovim + // ZZ in neovim writes to disk only if changes are made + // whereas :wq always writes to disk + /* $, 0, w, b, e movements now handled by text object fallback */ mapn("%", buf_find_matching_bracket, "match bracket"); mapv("%", buf_find_matching_bracket, "match bracket"); @@ -162,6 +167,11 @@ void normal_mode_bindings() { mapn("zR", kb_fold_open_all, "open all folds"); mapn("zz", buf_center_screen, "center screen"); mapn("~", kb_toggle_case, "toggle case"); + + // one-offs + mapn("D", kb_delete_to_line_end, "del to line end"); + mapn("C", buf_change_to_line_end, "change to line end"); + mapn("S", buf_change_line, "change line"); } void user_keybinds_init(void) { diff --git a/src/keybinds_builtins.c b/src/keybinds_builtins.c index 5a510b6..2d4d6ab 100644 --- a/src/keybinds_builtins.c +++ b/src/keybinds_builtins.c @@ -318,6 +318,17 @@ void kb_delete_line(void) { buf_delete_selection(&sel); } +void kb_delete_to_line_end(void) { + ASSERT_EDIT(buf, win); + + TextSelection sel; + if (!textobj_to_line_end(buf, win->cursor.y, win->cursor.x, &sel)) + return; + + buf_delete_selection(&sel); + win->cursor.x = sel.start.col > 0 ? sel.start.col - 1 : 0; +} + void kb_yank_line(void) { BUFWIN(buf, win) buf_yank_line_in(buf); diff --git a/src/keybinds_builtins.h b/src/keybinds_builtins.h index 52aad64..f6da0e6 100644 --- a/src/keybinds_builtins.h +++ b/src/keybinds_builtins.h @@ -17,6 +17,7 @@ void kb_enter_insert_mode(void); void kb_append_mode(void); void kb_enter_command_mode(void); void kb_delete_line(void); +void kb_delete_to_line_end(void); void kb_yank_line(void); void kb_paste(void); void kb_delete_char(void); diff --git a/test/test_textobj b/test/test_textobj index 21d7615..c7cfde0 100755 Binary files a/test/test_textobj and b/test/test_textobj differ