3

I know that Linux Desktops with a windowing manager such as X11-based systems have a system clipboard, but if not using a windowing manager, is there any clipboard?

For example, in Vim, the system clipboard can be accessed via the + register, but this only works in the GUI version of Vim running on X-windows since it is using the window manager's clipboard. If you are using text-based version of Vim, such as from a terminal or from a virtual console, it does not work. For example, if you open two different instances of Vim in different virtual consoles, how would you copy and paste between them?

  • Actually, X11 uses Selections, which require inter-client communication (and when the client terminates, the selection is gone). There is no system-wide clipboard, unless you run a client like xclipboard that takes over the selection from the client providing it. – dirkt Jan 3 '18 at 10:38
  • Interesting how none of the existing clipboard solutions can be decoupled from their parent application, be it X, gpm, tmux, or whatever. A clipboard facility that is accessible from all of these without requiring heavyweight solutions like a GUI would be very desirable. – phg Jul 24 '18 at 7:15
6

screen and tmux support copy-paste buffers, so that’s one possible approach (see the other answer for details).

Using only Linux virtual consoles, you can run gpm (or its libinput replacement, consolation) to provide mouse-based copy-paste: select text with the left mouse button, paste it with the middle mouse button.

Neither of these have direct integration with Vim as far as I’m aware, so you’re limited to copying what’s visible on screen or in the scrollback buffers if anything.

  • 1
    re: gpm for libinput -- are you thinking of consolation? – quixotic Jan 2 '18 at 14:45
  • i wasn't aware of it previously so thanks for mentioning! – quixotic Jan 2 '18 at 15:15
2

tmux has "paste buffers" which are similar to the X clipboard, and are accessible across different sessions running on the same host. Start each vim instance in a tmux session (either both in a single session, or each in its own - it doesn't matter for these purposes), and you can copy and paste text between them with ease:

Assuming the default key bindings for tmux, you can enter copy mode by pressing CTRL+B[. Navigate to the start of the text you want to copy and hit CTRL+SPACE, move the cursor to highlight the text you want and hit ENTER. This copies the selection to a paste buffer. Now you can switch to the other vim session (or any other program running under tmux), and press CTRL+B] to paste the buffer contents in the current pane.

tmux maintains multiple paste buffers; you can press CTRL+B# to see them all, or CTRL+B= to visually select a paste buffer and insert its contents in the current pane.

0

When X is running Vim is just pulling from xclip. This means copy-paste between applications that most people are thinking of really is an X feature.

While many applications have copy-paste functions or buffers to really be a clipboard it needs to be a shared function between applications through some form of IPC.

Both the big toolkits actually support this in a way over dbus. Even if in the background they are using X anyway the point is that these are interfaces that other applications can use.

https://developer.gnome.org/gtk3/stable/gtk3-Clipboards.html

http://doc.qt.io/qt-5/qclipboard.html

Both interfaces abstract the underlying Windowing systems clipboard so this would include working with Wayland which is more generic concept of "data sharing"

https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-data-sharing

On the console technically copy and paste is the same thing as saving and loading any buffer so just redirect what you need. So this is copy and paste at the OS level:

mkfifo clipboard && (echo -e "$copy" > clipboard && rm clipboard) &
paste=$(<clipboard)

At the bash/command interpreter level copy and paste is just:

copy="some text"
echo $copy

Also I realize the first also uses variables. But its using features of the OS as a demonstration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.