Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why it is so difficult for vim to copy into system clipboard?

Tags:

vim

According to official vim wiki copying any text into system clipboard is a something I've never expected to see in a text editor created by humans.

gg"+yG – copy the entire buffer into + (normal mode)

Copy/Pasting between the browser and a text file with 6 keystrokes is something I refuse to accept as normality.

Are there any sane alternatives?

like image 525
minerals Avatar asked Sep 08 '25 09:09

minerals


1 Answers

It's not difficult, it's powerful. As the yank command takes a {motion}, you can copy arbitrary (and precisely selected) text areas, all with the same command. Likewise, "+ is just one destination of many, and Vim's named registers are very useful.

You may have noticed that most people (sometimes heavily) customize their Vim setup. On top of the powerful editing abstractions, that puts it on yet another level (at the expense of now being dependent on your Vim configuration).

So, if you need to copy the entire buffer to the system clipboard often, create your own shortcut, and persist it in your ~/.vimrc. For example:

:nnoremap <F2> :%yank +<CR>

There you have it: copying with a single keystroke (cp. :help key-notation for how keys are specified; as function keys are sparse, I would prefer <Leader>y instead).

If you often yank (various areas) to the system clipboard, making that the default register might also be worthwhile:

:set clipboard^=unnamedplus
like image 111
Ingo Karkat Avatar answered Sep 10 '25 03:09

Ingo Karkat