Skip to content

Commit

Permalink
Add yank_to_clipboard commands, bind to <space>y by default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
the-mikedavis authored and archseer committed Jul 31, 2023
1 parent 4555a6b commit d4f9716
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion book/src/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ This layer is a kludge of mappings, mostly pickers.
| `w` | Enter [window mode](#window-mode) | N/A |
| `p` | Paste system clipboard after selections | `paste_clipboard_after` |
| `P` | Paste system clipboard before selections | `paste_clipboard_before` |
| `y` | Join and yank selections to clipboard | `yank_joined_to_clipboard` |
| `y` | Yank selections to clipboard | `yank_to_clipboard` |
| `Y` | Yank main selection to clipboard | `yank_main_selection_to_clipboard` |
| `R` | Replace selections by clipboard contents | `replace_selections_with_clipboard` |
| `/` | Global search in workspace folder | `global_search` |
Expand Down
12 changes: 12 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ impl MappableCommand {
later, "Move forward in history",
commit_undo_checkpoint, "Commit changes to new checkpoint",
yank, "Yank selection",
yank_to_clipboard, "Yank selections to clipboard",
yank_to_primary_clipboard, "Yank selections to primary clipboard",
yank_joined, "Join and yank selections",
yank_joined_to_clipboard, "Join and yank selections to clipboard",
yank_main_selection_to_clipboard, "Yank main selection to clipboard",
Expand Down Expand Up @@ -3762,6 +3764,16 @@ fn yank(cx: &mut Context) {
exit_select_mode(cx);
}

fn yank_to_clipboard(cx: &mut Context) {
yank_impl(cx.editor, '*');
exit_select_mode(cx);
}

fn yank_to_primary_clipboard(cx: &mut Context) {
yank_impl(cx.editor, '+');
exit_select_mode(cx);
}

fn yank_impl(editor: &mut Editor, register: char) {
let (view, doc) = current!(editor);
let text = doc.text().slice(..);
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
"C-v" | "v" => vsplit_new,
},
},
"y" => yank_joined_to_clipboard,
"y" => yank_to_clipboard,
"Y" => yank_main_selection_to_clipboard,
"p" => paste_clipboard_after,
"P" => paste_clipboard_before,
Expand Down

0 comments on commit d4f9716

Please sign in to comment.