readline style insert mode

pull/1039/head
Bob Qi 3 years ago
parent 7c9f620236
commit 0d1dd4603e

@ -239,6 +239,19 @@ Mappings in the style of [vim-unimpaired](https://github.com/tpope/vim-unimpaire
| `Escape` | Switch to normal mode | `normal_mode` |
| `Ctrl-x` | Autocomplete | `completion` |
| `Ctrl-w` | Delete previous word | `delete_word_backward` |
| `Alt-b`, `Alt-Left` | Backward a word |
| `Ctrl-b`, `Left` | Backward a char |
| `Alt-f`, `Alt-Right` | Forward a word |
| `Ctrl-f`, `Right` | Forward a char |
| `Ctrl-e`, `End` | move to line end |
| `Ctrl-a`, `Home` | move to line start |
| `Ctrl-w` | delete previous word |
| `Ctrl-u` | delete to start of line |
| `Ctrl-k` | delete to end of line |
| `backspace`, `Ctrl-h` | delete previous char |
| `delete`, `Ctrl-d` | delete previous char |
| `Ctrl-p`, `Up` | move to previous line |
| `Ctrl-n`, `Down` | move to next line |
## Select / extend mode

@ -185,6 +185,7 @@ impl Command {
copy_selection_on_prev_line, "Copy selection on previous line",
move_next_word_start, "Move to beginning of next word",
move_prev_word_start, "Move to beginning of previous word",
move_prev_word_end, "Move to end of previous word",
move_next_word_end, "Move to end of next word",
move_next_long_word_start, "Move to beginning of next long word",
move_prev_long_word_start, "Move to beginning of previous long word",
@ -279,6 +280,9 @@ impl Command {
delete_char_backward, "Delete previous char",
delete_char_forward, "Delete next char",
delete_word_backward, "Delete previous word",
delete_word_forward, "Delete next word",
kill_to_line_start, "Delete content till the start of the line",
kill_to_line_end, "Delete content till the end of the line",
undo, "Undo change",
redo, "Redo change",
yank, "Yank selection",
@ -563,6 +567,16 @@ fn extend_to_line_start(cx: &mut Context) {
goto_line_start_impl(view, doc, Movement::Extend)
}
fn kill_to_line_start(cx: &mut Context) {
extend_to_line_start(cx);
delete_selection(cx);
}
fn kill_to_line_end(cx: &mut Context) {
extend_to_line_end(cx);
delete_selection(cx);
}
fn goto_first_nonwhitespace(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);
@ -639,6 +653,10 @@ fn move_prev_word_start(cx: &mut Context) {
move_word_impl(cx, movement::move_prev_word_start)
}
fn move_prev_word_end(cx: &mut Context) {
move_word_impl(cx, movement::move_prev_word_end)
}
fn move_next_word_end(cx: &mut Context) {
move_word_impl(cx, movement::move_next_word_end)
}
@ -3802,6 +3820,19 @@ pub mod insert {
doc.set_selection(view.id, selection);
delete_selection(cx)
}
pub fn delete_word_forward(cx: &mut Context) {
let count = cx.count();
let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);
let selection = doc
.selection(view.id)
.clone()
.transform(|range| movement::move_next_word_start(text, range, count));
doc.set_selection(view.id, selection);
delete_selection(cx)
}
}
// Undo / Redo

@ -651,19 +651,35 @@ impl Default for Keymaps {
"esc" => normal_mode,
"backspace" => delete_char_backward,
"C-h" => delete_char_backward,
"del" => delete_char_forward,
"C-d" => delete_char_forward,
"ret" => insert_newline,
"tab" => insert_tab,
"C-w" => delete_word_backward,
"A-d" => delete_word_forward,
"left" => move_char_left,
"C-b" => move_char_left,
"down" => move_line_down,
"C-n" => move_line_down,
"up" => move_line_up,
"C-p" => move_line_up,
"right" => move_char_right,
"C-f" => move_char_right,
"A-b" => move_prev_word_end,
"A-left" => move_prev_word_end,
"A-f" => move_next_word_start,
"A-right" => move_next_word_start,
"pageup" => page_up,
"pagedown" => page_down,
"home" => goto_line_start,
"C-a" => goto_line_start,
"end" => goto_line_end_newline,
"C-e" => goto_line_end_newline,
"C-k" => kill_to_line_end,
"C-u" => kill_to_line_start,
"C-x" => completion,
});

Loading…
Cancel
Save