From ce7ad2beb5b763e55cc40933d70ca7c7b325292e Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Wed, 1 Sep 2021 11:01:19 +0900 Subject: Reimplement keep-pipe, it needs to manipulate selections, not text --- book/src/keymap.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'book') diff --git a/book/src/keymap.md b/book/src/keymap.md index d85fb936..2c6a9576 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -124,13 +124,13 @@ in reverse, or searching via smartcase. ### Shell -| Key | Description | Command | -| ------ | ----------- | ------- | -| `\|` | Pipe each selection through shell command, replacing with output | `shell_pipe` | -| `A-\|` | Pipe each selection into shell command, ignoring output | `shell_pipe_to` | -| `!` | Run shell command, inserting output before each selection | `shell_insert_output` | -| `A-!` | Run shell command, appending output after each selection | `shell_append_output` | -| `$` | Pipe each selection into shell command, removing if the command exits >0 | `shell_keep_pipe` | +| Key | Description | Command | +| ------ | ----------- | ------- | +| `\|` | Pipe each selection through shell command, replacing with output | `shell_pipe` | +| `A-\|` | Pipe each selection into shell command, ignoring output | `shell_pipe_to` | +| `!` | Run shell command, inserting output before each selection | `shell_insert_output` | +| `A-!` | Run shell command, appending output after each selection | `shell_append_output` | +| `$` | Pipe each selection into shell command, keep selections where command returned 0 | `shell_keep_pipe` | ## Select / extend mode -- cgit v1.2.3-70-g09d2 From 825bceeab68276cdf120bda5d172b854867d8585 Mon Sep 17 00:00:00 2001 From: oberblastmeister Date: Wed, 1 Sep 2021 11:55:16 -0400 Subject: add_newline unimpaired mapping (#653) * added some keymaps * remove * remove wrong mappings * remove * wrong import * use enum * correct line ending * added to book * column--- book/src/keymap.md | 23 ++++++++++++----------- helix-term/src/commands.rs | 36 ++++++++++++++++++++++++++++++++++++ helix-term/src/keymap.rs | 2 ++ 3 files changed, 50 insertions(+), 11 deletions(-) (limited to 'book') diff --git a/book/src/keymap.md b/book/src/keymap.md index 2c6a9576..861e46ac 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -110,17 +110,18 @@ in reverse, or searching via smartcase. | `N` | Add next search match to selection | `extend_search_next` | | `*` | Use current selection as the search pattern | `search_selection` | -### Diagnostics - -> NOTE: `[` and `]` will likely contain more pair mappings in the style of -> [vim-unimpaired](https://github.com/tpope/vim-unimpaired) - -| Key | Description | Command | -| ----- | ----------- | ------- | -| `[d` | Go to previous diagnostic | `goto_prev_diag` | -| `]d` | Go to next diagnostic | `goto_next_diag` | -| `[D` | Go to first diagnostic in document | `goto_first_diag` | -| `]D` | Go to last diagnostic in document | `goto_last_diag` | +### Unimpaired + +Mappings in the style of [vim-unimpaired](https://github.com/tpope/vim-unimpaired) + +| Key | Description | Command | +| ----- | ----------- | ------- | +| `[d` | Go to previous diagnostic | `goto_prev_diag` | +| `]d` | Go to next diagnostic | `goto_next_diag` | +| `[D` | Go to first diagnostic in document | `goto_first_diag` | +| `]D` | Go to last diagnostic in document | `goto_last_diag` | +| `[space` | Add newline above | `add_newline_above` | +| `]space` | Add newline below | `add_newline_below` | ### Shell diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 5574afbf..3bd63ab4 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -227,6 +227,8 @@ impl Command { select_mode, "Enter selection extend mode", exit_select_mode, "Exit selection mode", goto_definition, "Goto definition", + add_newline_above, "Add newline above", + add_newline_below, "Add newline below", goto_type_definition, "Goto type definition", goto_implementation, "Goto implementation", goto_file_start, "Goto file start/line", @@ -4473,3 +4475,37 @@ fn suspend(_cx: &mut Context) { #[cfg(not(windows))] signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP).unwrap(); } + +fn add_newline_above(cx: &mut Context) { + add_newline_impl(cx, Open::Above); +} + +fn add_newline_below(cx: &mut Context) { + add_newline_impl(cx, Open::Below) +} + +fn add_newline_impl(cx: &mut Context, open: Open) { + let count = cx.count(); + let (view, doc) = current!(cx.editor); + let selection = doc.selection(view.id); + let text = doc.text(); + let slice = text.slice(..); + + let changes = selection.into_iter().map(|range| { + let (start, end) = range.line_range(slice); + let line = match open { + Open::Above => start, + Open::Below => end + 1, + }; + let pos = text.line_to_char(line); + ( + pos, + pos, + Some(doc.line_ending.as_str().repeat(count).into()), + ) + }); + + let transaction = Transaction::change(text, changes); + doc.apply(&transaction, view.id); + doc.append_changes_to_history(view.id); +} diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index f3e160b1..71ac01a9 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -412,10 +412,12 @@ impl Default for Keymaps { "[" => { "Left bracket" "d" => goto_prev_diag, "D" => goto_first_diag, + "space" => add_newline_above, }, "]" => { "Right bracket" "d" => goto_next_diag, "D" => goto_last_diag, + "space" => add_newline_below, }, "/" => search, -- cgit v1.2.3-70-g09d2