on master help sign in
Add yank_to_clipboard commands, bind to `<space>y` by default

The clipboard special registers are able to retain multiple selections and also join the value when copying it to the clipboard. So by default we should yank regularly to the '*' and '+' registers. That will have the same behavior for the clipboards but will allow pasting multiple selections if the clipboard doesn't change between yanks.

commitd4f9716fbc36bc20848b7be0b65551495fa52952 authorMichael Davis <mcarsondavis@gmail.com> dateTue 11 Jul 2023, 11:15 (3 years ago) parent4555a6b
3 files changed+14−2
book/src/keymap.md+1−1 helix-term/src/commands.rs+12 helix-term/src/keymap/default.rs+1−1
book/src/keymap.md+1−1
@@ -291,7 +291,7 @@ This layer is a kludge of mappings, mostly pickers.
291291| `w` | Enter [window mode](#window-mode) | N/A |
292292| `p` | Paste system clipboard after selections | `paste_clipboard_after` |
293293| `P` | Paste system clipboard before selections | `paste_clipboard_before` |
294−| `y` | Join and yank selections to clipboard | `yank_joined_to_clipboard` |
294+| `y` | Yank selections to clipboard | `yank_to_clipboard` |
295295| `Y` | Yank main selection to clipboard | `yank_main_selection_to_clipboard` |
296296| `R` | Replace selections by clipboard contents | `replace_selections_with_clipboard` |
297297| `/` | Global search in workspace folder | `global_search` |
helix-term/src/commands.rs+12
@@ -375,6 +375,8 @@ impl MappableCommand {
375375 later, "Move forward in history",
376376 commit_undo_checkpoint, "Commit changes to new checkpoint",
377377 yank, "Yank selection",
378+ yank_to_clipboard, "Yank selections to clipboard",
379+ yank_to_primary_clipboard, "Yank selections to primary clipboard",
378380 yank_joined, "Join and yank selections",
379381 yank_joined_to_clipboard, "Join and yank selections to clipboard",
380382 yank_main_selection_to_clipboard, "Yank main selection to clipboard",
@@ -3762,6 +3764,16 @@ fn yank(cx: &mut Context) {
37623764 exit_select_mode(cx);
37633765}
37643766
3767+fn yank_to_clipboard(cx: &mut Context) {
3768+ yank_impl(cx.editor, '*');
3769+ exit_select_mode(cx);
3770+}
3771+
3772+fn yank_to_primary_clipboard(cx: &mut Context) {
3773+ yank_impl(cx.editor, '+');
3774+ exit_select_mode(cx);
3775+}
3776+
37653777fn yank_impl(editor: &mut Editor, register: char) {
37663778 let (view, doc) = current!(editor);
37673779 let text = doc.text().slice(..);
helix-term/src/keymap/default.rs+1−1
@@ -265,7 +265,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
265265 "C-v" | "v" => vsplit_new,
266266 },
267267 },
268− "y" => yank_joined_to_clipboard,
268+ "y" => yank_to_clipboard,
269269 "Y" => yank_main_selection_to_clipboard,
270270 "p" => paste_clipboard_after,
271271 "P" => paste_clipboard_before,