Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I yank to clipboard? #1099

Closed
AnthonyJacob opened this issue Dec 30, 2016 · 14 comments
Closed

How do I yank to clipboard? #1099

AnthonyJacob opened this issue Dec 30, 2016 · 14 comments

Comments

@AnthonyJacob
Copy link

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

@doppioandante
Copy link
Contributor

Look at this entry: https://github.com/mawww/kakoune/wiki/Registers-&-Clipboard#using-the-system-clipboard

@dbazuin
Copy link

dbazuin commented Dec 31, 2016

On Macos this works also

use pbcopy for copy and paste

hook global NormalKey y|d|c %{ nop %sh{
printf %s "$kak_reg_dquote" | pbcopy
}}

@mabbamOG
Copy link

mabbamOG commented Jun 4, 2017

has this been implemented? im interested in using kak for small simple editing but actually having to configure the most basic of functionalities is offputting

@bhajneet
Copy link
Contributor

bhajneet commented Jun 4, 2017

It has not. But configuring this should not be that difficult:

  • make sure you have "xclip" installed on your system
  • open ~/.config/kak/kakrc (or equivalent on your system)
  • paste this into there and save the file:

map global user y '<a-|>xclip -i -selection clipboard<ret>'

Now if you hit ,y it will be yanked to your clipboard.

@bhajneet
Copy link
Contributor

bhajneet commented Jun 4, 2017

Assuming you want to also paste things into kakoune from your clipboard here is the line for that:

map global user p '!xclip -o<ret>'

Similarly you use ,p to paste into kakoune from the clipboard.

@josephrocca
Copy link
Contributor

josephrocca commented May 24, 2019

@mawww is there any hope of making this build-in with some simple command? I followed this: https://stackoverflow.com/a/42296453/10898116 and got copy/paste working, but it seems fairly elaborate (required installing xsel, for starters) and might turn people away from kakoune. Maybe it's more technically difficult than I appreciate?

@SolitudeSF
Copy link
Contributor

copying one snippet and installing one program is complicated?

@Screwtapello
Copy link
Contributor

More complicated than just a snippet, which in turn is more complicated than "it just works the way I expect". These things are always relative.

@alexherbo2
Copy link
Contributor

# Yank
hook global NormalKey '[ydc]' %{
  nop %sh{
    (printf '%s' "$kak_main_reg_dquote" | xclip -filter | xclip -selection clipboard) < /dev/null > /dev/null 2>&1 &
  }
}

# Paste
map global user p -docstring 'Paste (After)' '<a-!>xclip -out -selection clipboard<ret>'
map global user P -docstring 'Paste (Before)' '!xclip -out -selection clipboard<ret>'
map global user R -docstring 'Replace' '|xclip -out -selection clipboard<ret>'

@josephrocca
Copy link
Contributor

@SolitudeSF If it's quite hard to build basic copy/paste functionality into the kakoune by default, then that's completely understandable. If not, then it's obviously a needless complication for users that should be addressed.

@Screwtapello
Copy link
Contributor

It'd be pretty easy for, say, Cygwin's clipboard support, where you can just read and write /dev/clipboard.

It'd be a bit more complex for macOS, since you can shell out to pbcopy and pbpaste, but I'm not sure if/how those work if you're running code on a macOS box via SSH instead of via the GUI.

It'd be more complex yet again for X11, since X11 doesn't provide a place to store clipboard data, it just stores "which application last copied", so the application has to stay running at least until some other application copies. Since Kakoune is single-threaded, long-running, blocking processes are annoying (although not impossible) to deal with, as in #2325.

It'd be even more complex for Wayland, since for security reasons Wayland only allows an application to copy to the clipboard while it's processing an input event, like a mouse-click on a "copy" toolbar button, or a "Ctrl-C" keyboard event. Since Kakoune runs inside a terminal, it never gets to see Wayland input events, and so it couldn't interact with the clipboard... EXCEPT that most Wayland servers are running XWayland, so you can just use the X11 solution, EXCEPT that XWayland is not guaranteed to be present, and Kakoune would probably fail in a very confusing and difficult-to-debug fashion in that case.

Supporting all of the above would be much more complex than any of them individually, just because new features are always multiplicative rather than additive.

As a point of comparison, Vim decided to take on the complexity of multiple native ports long ago, so it already supports all those clipboard APIs and more. In fact, Vim's so portable that one of the early goals of the NeoVim fork was to make it less portable, in the name of maintainability. From that point of view, Kakoune's already way ahead of the curve, since it only supports one platform, POSIX. Sadly, the POSIX standard doesn't include any kind of clipboard API.

@asmarcz
Copy link

asmarcz commented May 16, 2020

Assuming you want to also paste things into kakoune from your clipboard here is the line for that:

map global user p '!xclip -o<ret>'

Similarly you use ,p to paste into kakoune from the clipboard.

In addition to @bhajneet answer, you might want to also use the proper selection for pasting. For me it was causing the use of "middle-click clipboard" instead of the "classic one".

map global user y '<a-|>xclip -i -selection clipboard<ret>'
map global user p '!xclip -selection clipboard -o<ret>'

@razetime
Copy link
Contributor

Look at this entry: https://github.com/mawww/kakoune/wiki/Registers-&-Clipboard#using-the-system-clipboard

link to new page: https://github.com/mawww/kakoune/wiki/Registers---Clipboard

@DerSaidin
Copy link
Contributor

Also note, if you want the clipboard to work across ssh, you need to enable trusted X11 forwarding.

There are two ways to do this:

  • connect with -Y: ssh -Y host
  • add ForwardX11 options to ~/.ssh/config for the host like...
Host a
    Hostname a.example.com
    User auser
    ForwardX11 yes
    ForwardX11Trusted yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests