Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/buf/buf_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Binary file modified src/buf/buf_helpers.h
Binary file not shown.
1 change: 1 addition & 0 deletions src/commands/cmd_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions src/keybinds_builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/keybinds_builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Binary file modified test/test_textobj
Binary file not shown.