How do I yank to system clipboard in Kakoune?
Asked Answered
S

5

11

If I yank a word in kakoune, how do I paste it into another editor (e.g. gedit)?

I have read How to make vim paste from (and copy to) system's clipboard? since vim is very similar but kakoune does not have any * register.

Searcy answered 30/12, 2016 at 13:12 Comment(3)
Have you checked this link ?Isoleucine
Can't you wait a bit?Sammysamoan
@Sammysamoan I have thought about it but : 1) this kind of question does not fit github issue well 2) there will be probably more people who will be confused as I wasSearcy
C
13

In case all the links go away this is the complete solution:

<a-|> xsel --input --clipboard <ret>

Explanation:

  • <a-|> pipes the current selection to what follows.
  • xsel is a program for manipulating X's clipboard.
  • --input tells xsel to read from stdin.
  • --clipboard tells xsel which 'selection' store to use. There are three of them and you want 'clipboard' in order to paste elsewhere.

This will work on Linux. Not sure about MacOS, I'd imagine piping to pbcopy would Just Work.

EDIT: To make live easier define a key binding in User mode like so (in your .kakrc):

map global user y '<a-|>xsel -i -b<ret>'

Now you can select the text and press ,y to yank to the system clipboard. The leading comma tells Kakoune to look for the key binding in User mode.

Cohdwell answered 17/2, 2017 at 11:11 Comment(4)
Actually, --input (-i) can be omitted. Default behaviour of xsel when its stdout and stdin are not tty is to read from stdin, and if stdin is tty then default behaviour is to write to stdout. Also, --clipboard can be abbreviated to -b. Or omitted altogehter if you want to copy to "primary selection" rather than clipboard.Oto
<a-|> xsel -i -b worked for me after installing xsel. Wasn't able to shorten it further. It's a shame that it's this complicated for something so simple.Irrepressible
@Joe I've updated my answer to provide a shorter solution.Cohdwell
A simple, naked xsel saves to primary, xsel -b to clip.Radius
C
3

To add to the accepted answer, according to the documentation if your version of Kakoune is post July 2020 then you can add the following hook to your kakrc:

hook global RegisterModified '"' %{ nop %sh{
  printf %s "$kak_main_reg_dquote" | xsel --input --clipboard
}}
Cienfuegos answered 8/4, 2021 at 12:37 Comment(2)
It's not a keybinding, it's a hook that runs xsel every time anything gets yanked, thus keeping system clipboard in sync with the main "copy" registerRadius
@Radius Thank you for your correction. I have amended the answer.Cienfuegos
M
2

Just so you are aware, there is also a great plugin to help with this issue. Kakboard works everywhere, including Mac, Xorg and even Wayland environments. You can also set your own custom command in more exotic environments by setting the kakboard_(copy|paste)_cmd options.

Motorcar answered 3/11, 2019 at 18:24 Comment(0)
S
0

So it turns out you need to install xsel and then follow this guide on wiki.

Searcy answered 30/12, 2016 at 17:48 Comment(0)
V
0

Cross-platform, or platform-agnostic solution:

The system clipboard will update automatically when you yank.

Note, for linux, I use wl-copy for wayland.

hook global RegisterModified '"' %{ nop %sh{
    case $(uname) in
        Linux)
            wl-copy -n "$kak_main_reg_dquote" > /dev/null 2>&1 & ;; 
        Darwin)
            printf "%s" "$kak_main_reg_dquote" | pbcopy ;;
        esac
}}
Vagabond answered 25/11, 2021 at 5:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.