286

For X11-based systems (ie. Linux and most other UNIX-like systems) there are two clipboards which are independent of each other: PRIMARY - This is copy-on-select, and can be pasted with the middle mouse button. CLIPBOARD - This is copied with (usually) ^C, and pasted with ^V (It's like MS Windows). OS X and Windows systems only have one clipboard. For X11 ...


25

So, installing vim-enhanced and vim-X11 is enough, but is not at the same time. To enable the system funtcions like +clipboard, you moreover need to use the vimx executable rather than vim or vi (even though they are probably identical, the name changes the behaviour). One way how to do that permanently is by adding aliases in your .bashrc file: alias vi='...


16

The other answers cover how to copy text from your buffer into the system clipboard. Another common operation is to copy text from another register to the clipboard. For example, if you've already yanked some text into " (the default register), you might want to load that register into the clipboard. You can do this with :let: let @+=@" — copies the ...


14

From http://vim.wikia.com/wiki/Accessing_the_system_clipboard set clipboard=unnamedplus This changes the default Vim register to the + register, which is linked to the system clipboard. From :h clipboard-unnamedplus: clipboard-unnamedplus unnamedplus A variant of the "unnamed" flag which uses the ...


13

Ok. Apparently on native vim in Arch there is no support for X so the +clipboard feature is missing. To fix this, install gvim, which although conflicts with vim, which was my initial problem with it, retains the exact same functionality if you use vim Rather than, gvim You still need to set clipboard=unnamed.


12

TL;DR: This isn't really possible without a clipboard manager (e.g. clipit, diodon, glipper, parcellite). It's an explicit design choice of X to not store the data for the X selections, whether that's the PRIMARY (what Vim calls "*) or CLIPBOARD (what Vim calls "+) selection. When a user performs a copy in an application, the application just tells X Hey, ...


11

OK, here is a "yank & put" primer… In Vim, the primary commands for yanking (copying) and putting (pasting) are y and p. Yanking places the yanked text in a register. That register is the unnamed register, ", by default but one can use other registers: "ay " yank into register a "by " yank into register b "+y " yank into clipboard register […]...


7

VIM has another setting pastetoggle that defines the mapping for toggling paste mode. That's what you'd want to do and then you can just enable paste mode and then paste. Although I find that a little less intuitive and have often found ]p to be a better way to paste code instead of using just p


7

On builds that support it, the register named * is the system clipboard. To copy text from Vim to the system clipboard, you can select the text using visual mode, then press "*y to copy it to the system clipboard. Conversely, use "*p to paste text from the system clipboard into Vim.


7

A few <expr> mapping should be able to do the job here. The basic structure would be function! ClipboardOrXclip(command, register) if a:register !~ '[+*]' || has('xterm_clipboard') || has('gui_running') " Just return the original command if the clipboard is accessible " or it's not a register that should be handled by xsel ...


7

Do you need to use the mouse (middle-klick)? I'd go for a macro: Press qq to start recording Press i"Esc"*p`]a",Esc to first insert the first set of quote, then paste from the system clipboard, go to the end of the paste and append quote and comma Press q to stop recording Then, each time you want to paste that way, simply hit @q. Note: If you're on X, ...


7

I'm aware this is a very old question but I recently found a good solution. After much frustration, I came across these ways to access the windows system clipboard by copying and pasting. By copying, with vim version >= 8.0.1394, as noted in another answer https://vi.stackexchange.com/a/15190 let s:clip = '/mnt/c/Windows/System32/clip.exe' if executable(s:...


6

You can assign to the clipboard with the special + register: :let @+ = expand('%:p') If you want to make this easier, you could create a command, so you only have to type :CopyBuffer: :command! CopyBuffer let @+ = expand('%:p') and/or map it to a key: :nnoremap <Leader>c :let @+=expand('%:p')<CR> The post "How can I copy text to the system ...


6

Note: This only applies in unix with X11 environments. The "highlighted text" clipboard is known as the PRIMARY X selection (vs SECONDARY or CLIPBOARD X selections). Vim, when built with X support, provides access to the PRIMARY and CLIPBOARD selections via the registers *, + (you can find more information in :help quoteplus and :help quotestar) So, to ...


5

If you are using a fairly modern terminal emulator, you can install the vim-bracketed-paste plugin. From the docs: xterm, urxvt, iTerm2, gnome-terminal (and other terminals using libvte) are known to work. After installing, you can simply paste as normal in insert mode, and it will take care of setting and unsetting paste for you.


5

I recommend you use Gvim, and add this to your .vimrc: source $VIMRUNTIME/mswin.vim behave mswin This enables support for CtrlC, CtrlX, CtrlV like notepad in Windows. Note that this will also add some other common Windows shortcuts, such as CtrlS for :w, CtrlA for select all, etc.


5

I understand that you are set up with the features necessary for copy and pasting with the system clipboard, but I want to be a tad redundant as those registers can be a tad challenging to set up. It's all about the features that are enabled with your install of Vim. In OS X and Linux, the clipboard feature needs to be enabled, and Linux usually also ...


5

I got around the problem I posted. I am leaving the solution if and when anyone gets stuck in similar situations. Put this snippet into your init.nvim. Then install xclip. For easy manipulation you can also use some gui clipboard manager like xfce4-clipman. But xclip is necessary for the following snippet. let g:clipboard = { \ 'name': 'xclip-xfce4-...


4

vim doesn't need gnome or gtk to get +clipboard, but it does need x11. From my tests, the minimum amount of dependencies needed are the xorg header files and x11 dbus support. In Debian apt-get install x11-dev dbus-x11 will do the job. Then you can ./configure --with-features=huge and vioala, +clipboard


4

MacVim Under OS X, it's best to use MacVim. OS X behaves differently to other operating systems when it comes to things like clipboard management. MacVim is specifically designed to address the areas where Vim falls short on the Mac. Coming to a terminal near you Although MacVim runs as a GUI (like GVim) by default, you can use MacVim in the terminal ...


4

You wouldn't have to spam us with all those questions if you took the time to read — and try to understand — the documentation. There is only one clipboard register, "+ and you can't append to that register directly like you could with "a-z, simply because there is no such thing as "capital +". If you want several yankings to end up in the clipboard ...


4

Removing a from the list of guioptions was the answer. Change it from set guioptions=ac to only set guioptions=c. Credit to carpetsmoker in the comments here Can visual select mode be integrated with the Unix selection clipboard?


4

I want to take a shot at answering my first question on this forum. If I understand your question right, you are referring to concepts of "clipboard" and "primary". If not - sorry, I am wrong. Note: After the comment by @jjaderberg below, I decided to clarify why I assumed that xterm_clipboard in vim is Primary. To be sure I looked up Clipboard definition ...


4

The trick is to enable the mouse with :set mouse=a. By default, Vim doesn't handle the mouse; the terminal emulator does, and from the terminal emulator's perspective "it's all text", it can't distinguish between your "number" or gutter. gVim "emulates" a terminal emulator in many ways, and acts in the same way. Then enabling the mouse, it's Vim that does ...


4

A good general rule when using Vim is to not use the mouse—Vim is designed from the ground up to be used with keyboard commands. In order to copy text, you can use the y command to yank a particular selection or chunk of text. Like all other Vim commands, you can think of y as a verb and give it modifiers, like y2j to yank the current line and the next ...


4

My UnconditionalPaste plugin provides a g,"p mapping that pastes each line in the register (prepend "+ for the system clipboard, as usual) surrounded by double quotes and delimited by commas, all in one line. This is just one particular variant from a plethora of similar mappings; some even query for the separator.


4

Assuming your vim includes clipboard support (:version shows +clipboard) and you intend to do this in more than one editing session, I would recommend creating a mapping that does this for you: nnoremap <F5> i"",<Esc>h"+P <F5>: what you'll hit to trigger the mapping. Could be any combination of keys. i"",<Esc>: "", and escape ...


4

There are few thing you can do to solve this. Homebrew compiled Huge version, while default Vim is in Normal version. Huge adds for example clipboard and more mouse/terminal support. This makes selecting with mouse actually select in Vim (so changes to Visual mode) instead of doing selection on terminal layer. Having that said, you can: press "+y or "*y in ...


4

Thank you to @Christian Brabandt for linking this in the comments: https://www.reddit.com/r/vim/comments/7pmv3d/workflows_that_work/dskyram/ Works great. Just put the following in your vimrc and make sure to have vim version >= 8.0.1394 " WSL yank support let s:clip = '/mnt/c/Windows/System32/clip.exe' " default location if executable(s:clip) augroup ...


4

While let @* and let @+ works, the recommended way to do it in the doc is to use setreg() like this: call setreg('+', @a) See :h setreg() which even contains an example of what you want to do: :call setreg('*', @%, 'ac') The third argument is used to specify the type of the register you want to copy. It is also used to append the register to the current ...


Only top voted, non community-wiki answers of a minimum length are eligible