2

I am given an account on a new server these days. The new server does not have x11 install, neither do I have sudo. So I cannot install system packages, and I cannot compile with the option -with-x.

But I still want to use vim when I am working on my server, and I need to use the clipboard feature to allow me to copy the contents from and to the vim and other places. How could I do this pleaes?

===== Edit: I got to find that the clipboard provided by the terminal can help. I could paste contents to vim with ctrl+shift+v. But the hot key of ctrl+shift+'c' does not work in the vim. how could I copy from vim like I copy from terminal?

3
  • Can't you compile Vim and install it to a directory owned by your user that you'll add to your $PATH? This way you shouldn't need sudo.
    – statox
    Apr 26, 2019 at 8:21
  • @statox Hi, I can compile my own vim, but I cannot use -with-x option anyway. Can I copy to system board without -with-x compiled? Apr 26, 2019 at 8:24
  • I would say that you don't need -X11, +clipboard should be enough but maybe I'm wrong.
    – statox
    Apr 26, 2019 at 8:29

3 Answers 3

3

Checking for X11-clipboard support in terminal

From the console, type:

vim --version | grep clipboard

If you see +clipboard or +xterm_clipboard, you are good to go. If it's -clipboard and -xterm_clipboard, you will need to look for a version of Vim that was compiled with clipboard support.

Installing clipboard support

On Debian and Ubuntu, to obtain clipboard support install the package vim-gtk or vim-gnome (not vim-tiny).

sudo apt install vim-gtk3 # go for vim-gtk if vim-gtk3 is not available

Reopen Vim and it should work.

For other operating systems and a reference, check this.

1

If you want to use the clipboard directly from Vim, you'll need a version compiled with either the +clipboard or +xterm_clipboard features. On non-macOS Unix systems, those generally require at least X11 libraries. Without those features, Vim itself has no way of talking to the clipboard. You'll also need X forwarding enabled on your SSH connection (ssh -X).

Without those features, you can copy and paste from your terminal, but the copy will be only from the data you highlight with your mouse (then copy with Ctrl-Shift-C), just like at the shell. You can also use a terminal multiplexor like screen or tmux (running your remote Vim inside them) and configure it to copy and paste regions from the screen.

0

First, install xclip (e.g., yay -S xclip).

Next, open your vim config file (e.g., ~/.config/nvim/init.vim).

Finally, add shortcuts:

set clipboard=unnamed,unnamedplus
nnoremap yy Vdugv<esc>
vnoremap y dugv<esc>
vnoremap p P        "<-- This is optional shortcut.
1
  • Mappings aren’t necessary but could use explanation. In particular the nnoremap on yy seems superfluous (and would be more simply yyV if the line selection was important to you). Similarly ygv should work in first xnoremap. Second is basically P in recent Vims.
    – D. Ben Knoble
    Nov 12, 2022 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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