1

So...I'm using Vim (in the terminal, not any sort of other gui; whenever Vim is used by itself, assume it's terminal vim).

Vim is decent, I actually don't find the learning curve to be too bad. I'm a bit less efficient than I would be in a normal text editor, though, primarily due to the act of switching to and from normal mode.

But there is one thing about vim that drives the nails in the coffin for me. Normally, when I press Ctrl+Shift+C in my terminal, it copies the text that I've highlighted to the window manager clipboard, and I can then paste that. Ctrl+C and Ctrl+V (or their variants) work absolutely fine in every application that I've used on my system.

With Vim, I can press Ctrl+Shfit+V and it will paste the data that I have in my clipboard. But for the life of me, Vim does not copy to the global clipboard. I have tried...

  • Ctrl+Shift+C with visual mode
  • using both "*y and "+y (or another copy command)
  • using set clipboard=unnamed and set clipboard=unnamedplus
  • installing gvim for "clipboard support" (for terminal vim) and repeating the other steps.

Vim just...refuses to copy to the clipboard.

But I had a thought. I don't need Vim copy to the clipboard itself. I just need it to stop blocking / intercepting the terminal's behavior for Ctrl+Shift+C in visual mode. But I'm still new to Vim, and I have absolutely no idea how one would accomplish this. All of my attempts to search for something this specific are rather vapid. This is my question to this form: is there a way to get Vim to allow the terminal emulator (Alacritty) to copy to it's clipboard using Ctrl+Shift+C? If someone with more Vim experience than myself could give me a pointer, I would really appreciate it.

My system, for reference, is Arch Linux using the Sway window manager with the Alacritty terminal emulator. I've seen various things about installing a clipboard manager for Sway, because default Sway doesn't hold the clipboard data if you exit the program you've copied the text from. However, I've never really had a problem with this; even when I quit a program completely, the data is still there. The default clipboard works absolutely fine for me and I don't necessarily want to install and configure a clipboard manager just to get vim to maybe work, unless it's the only option. This doesn't seem like the issue anyways.

Also, if it helps, the gvim standalone application does support copying to the clipboard, but standard terminal Vim does not. If possible, I would really like to use a terminal text editor. But I guess I'll just use the gvim app if nothing can be done.

3
  • can you check whether this is a classic vim-exclusive problem? A quick apt-get / zypper / pacman / … / dnf install neovim, followed by nvim would allow you to test whether the slightly reworked buffer architecture of the neovim fork works. Might help us know what to look into. Commented Feb 7 at 22:34
  • PS: I'm using awesome as window manager, and alacritty as my terminal emulator, and neovim just copies beautifully to clipboard. Commented Feb 7 at 22:35
  • There are many many ways of copy/past to/from vim that cannot be described in a single QA post. My favourite is xclip. To put highlighted text in xclip :'<,'>w !xclip . Note that the bit <,'> gets added automatically after you type :. And to read in the xclip into vim :r ! xclip -o. You can also read/write from buffers or temporary files -- more powerful and versatile that clipboards.
    – user167612
    Commented Feb 16 at 9:11

1 Answer 1

1

From How to copy text from vim to an external program?

Hold down the Shift key and select text with the mouse cursor. Text will be copied to the clipboard. This also works for pasting from the clipboard in to vim. To be clear, this works for vim running in a terminal such as xterm.

In my searches, I somehow didn't come across this before. This actually did after selecting the text, I could use Ctrl+Shift+C as normal.

Unfortunately, it copied line numbers as well, so I suppose I would have to disable those before copying. If anyone else has perhaps a more idiomatic way to do this, I would appreciate it.

EDIT: installing wl-clipboard was really simple, took a few KB on my system for something rather useful, and enabled the functionality of the + register. I also took others' advice and used nvim, which has worked flawlessly. Thanks all. Of course, if those things are prohibitive, see the above. And if you use XOrg, obviously you would use the x clipboard equivalent.

TLDR: Even with """clipboard support""", Vim expects there to be a copying utility/command, which you can configure. Vim automatically configures a certain number of these for you (see :help clipboard). You can also write your own. The problem is that my Vim had no way to access the Wayland system clipboard, as this wasn't configured. Installing wl-clipboard out of the gate fixed this issue because that is one of the clipboards that Vim supports out of the box.

4
  • 2
    To exclude the line numbers, etc., you'll need to enable Vim's mouse integration. See unix.stackexchange.com/q/139578/70524 for various options on that
    – muru
    Commented Feb 8 at 0:44
  • This is true, but the problem was that vim's internal mouse integration (visual mode, or at least I think you're talking about visual mode) didn't work for copying ("+y didn't copy to the system clipboard). Commented Feb 16 at 1:04
  • I think your post is mixing up Vim and Neovim: "Even with """clipboard support""", Vim expects there to be a copying utility/command, which you can configure" <- this is true of Neovim, which always uses some external utility for interfacing with the system clipboard. Vim always uses internal functionality instead (which of course need to be enabled at build time), and has to be configured (via maps to override existing shortcuts) to use external tools. If "+y didn't work, then your Vim didn't have the support enabled. Which package were you using? gvim or vim?
    – muru
    Commented Feb 16 at 1:52
  • I switched from vim to gvim and finally to nvim--all had the same problem. Apparently vim (referring to both) expects there to be a command that enables it to copy to the system clipboard. I fixed that by installing wl-clipboard. Commented Feb 21 at 4:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .