CLIPBOARD and PRIMARY registers don't work on my Linux - vim

If I want to copy/paste something to/from a register I have no problem.
For example if I'm in Visual Mode and I press "ay the selected region get correctly copied to register a (and if I press "ayy in Normal Mode, the line under the cursor get correctly copied into a).
During the sequence I can see the characters I pressed in the bottom bar.
If I try to hit one of the sequences "*yy, "*dd, "+yy or "+dd, when I press the double quotes they appear in the bottom bar, but when after this I press * or + the sequence in the bottom bar disappear and if I complete the sequence, it doesn't copy anything to the CLIPBOARD and PRIMARY selections.
System: ArchLinux
Window manager: suckless DWM
Terminal: bash on suckless ST

You're missing +clipboard support in your Vim.
On ArchLinux, you can get a Vim with +clipboard support by installing the gvim package.
See Vim Installation on the ArchLinux wiki, more specifically this note:
The vim package is built without Xorg support; specifically the +clipboard feature is missing, so Vim will not be able to operate with the primary and clipboard selection buffers. The gvim package provides also the CLI version of Vim with the +clipboard feature.
The gvim package will include a new gvim command for a GUI version of Vim, but it will also include a regular console vim command, only that one will have support for +clipboard when running inside a terminal attached to an X11 display.

Related

sublime text 3 complete vim support

I installed Vintageous in sublime text 3 so i can use some of vim commands and interactions. But I am using it for a long time, and there is a lot of features missing, like the 'ctrl+x' and 'ctrl+a" to decrease and increase a number, the 'ctrl+r' to redo, the 'ctrl+v' to select vertical blocks, 'ctrl+c' to quit insertion mode ... etc.
I really like sublime text 3, but in the other hand, i'm really missing this commands, it's all of theses commands which makes vim so powerful.
So how can I get a complete vim mode in sublime text 3. It would be just perfect if i can do that (because I really miss vim complete features).
PS : I'm using Ubuntu 15.10 with Linux version > 4.
Vintageous has the setting vintageous_use_ctrl_keys, which should solve most of your issues.In contrast to other packages Vintageous uses the User preferences. Hence you can just add the entry "vintageous_use_ctrl_keys": false to "Preferences >> Settings - User". However for this settings there is an entry in the control palette. Press ctrl+shift+p and write Vintageous: Toggle Vim Ctrl Keys. You can see the other settings here and just change them in the user preferences.
If you are still missing some keys I would recommend to look at the default keymap and search for other packages, which provide this behavior and change the keybinding as you want them.
Now there is a new player, ActualVim plugin.
Everything you like about using Sublime Text 3, and everything you
like about typing in vim.
Actual uses an embedded Neovim instance to accurately manipulate each
Sublime Text buffer as though you were editing the text directly in
vim, without breaking any Sublime Text features (aside from multiple
selection for now).
It’s way better than Vintage mode or Vintageous. You can use your own .vimrc, plugins, real vim motions and commands.
To get vim shortcuts in Sublime Text
Install neovim (the actual program which is unrelated to sublime text - it's necessary for this approach to work). Example brew install neovim.
In sublime, press command + shift + p, type "install package" and click on the top result.
Now search for 'ActualVim', and click on it, it should install.
Close and reopen sublime.
Vim shortcuts now work!

Vim clears system clipboard on start

I am using Vim 7.4.430 with +clipboard and +xterm_clipboard options on Ubuntu 14.04.1. When I start Vim with an empty .vimrc file, I can use "+p to paste text from system clipboard. I can, as well, call set clipboard^=unnamedplus in a running Vim instance and directly paste from system clipboard with only p.
However if I start with a .vimrc file that contains only the set clipboard^=unnamedplus, pressing p will give Nothing in register + error. And, actually I lose whatever text I have in the system clipboard.
This happens both in terminal vim and in vim gui.
Any suggestions?
I have introduced that bug with 7.4.396 and has been fixed with patch 7.4.445

Selection automatically put into X11 clipboard - VIM

In my previous Linux install, when I selected some text in visual mode (without the mouse!), it would automatically put it in my X11 clipboard. Then I could naturally paste this text anywhere else using the mouse middle button.
With my new Linux installation, this doesn't work anymore (merely selecting text in visual mode doesn't put it in X11 clipboard anymore).
How can I get this nice feature back?
(I am not interested into the "*y or "+y solutions, which by the way don't work on my system.)
Thanks in advance!
The visual selection (v, V, or CTRL-V) can automatically be copied to the
X11 selection (* buffer).
In non-gui mode the clipboard option controls this (only supported if
+xterm_clipboard appears when you type vim --version). In gui mode
guioptions controls it.
This makes all Visual mode selections automatically go to the X11 primary
selection:
set clipboard+=autoselect
set guioptions+=a
This turns it off:
set clipboard-=autoselect
set guioptions-=a
In vim see:
help 'clipboard'
(single quotes required)
Use:
set guioptions+=a
This works with the GUI (Gvim). Reference is at :help guioptions_a.
*guioptions_a* *'go-a'*
'a' Autoselect: If present, then whenever VISUAL mode is started,
or the Visual area extended, Vim tries to become the owner of
the windowing system's global selection. This means that the
Visually highlighted text is available for pasting into other
applications as well as into Vim itself. When the Visual mode
ends, possibly due to an operation on the text, or when an
application wants to paste the selection, the highlighted text
is automatically yanked into the "* selection register.
Thus the selection is still available for pasting into other
applications after the VISUAL mode has ended.
If not present, then Vim won't become the owner of the
windowing system's global selection unless explicitly told to
by a yank or delete operation for the "* register.
The same applies to the modeless selection.
When using Vim inside gnome-terminal on Arch and Gentoo Linux this functionality just works.
When using Vim inside Konsole this does not work.
Using gvim -v will launch a terminal version of GVim where set guioptions+=a works:
any text selected within that Vim is automatically copied to Linux's selection buffer.
To paste text from the selection buffer press the middle mouse button
On my Debian I got it working after installing vim-gnome package.
A comment from pkg-vim-maintainers mailing list instructs to install either vim-gtk, vim-gnome or vim-lesstif.
With my new installation of Kali, I solved the issue above by installing vim-gtk package for gnome-terminal. The vim-gtk package changes the "-xterm_clipboard" to "+xterm_clipboard", and the problem is solved. After selecting text in vim, the text will be copied to system clipboard automatically.

Copying text outside of Vim with set mouse=a enabled

After enabling set mouse=a, text copied inside of Vim will not paste outside of Vim. Does anybody know of a way to fix this?
Here, selecting text with the mouse turns on visual mode and disables the Copy option in the popup menu:
Press shift while selecting with the mouse. This will make mouse selection behave as if mouse=a was not enabled.
Note: this trick also applies to "middle button paste": if you want to paste in vim text that was selected outside, press shift while clicking the middle button. Just make sure that insert mode is activated when you do that (you may also want to :set paste to avoid unexpected effects).
OS X (mac):
hold alt/option while selecting (source)
Use ", +, y after making a visual selection either with the keyboard or the mouse. You shouldn’t be using the terminal’s copy command anyway, because that copies what the terminal sees instead of the actual content. Here is what this does:
",+ tells Vim to use the register named + for the next delete, yank or put. The register named + is a special register, it is the X11 clipboard register. (On other systems, you would use * instead, I think, see :help clipboard and :help x11-selection)
y is the yank command, which tells Vim to put the selection in the register named previously.
You could map it like this:
:vmap <C-C> "+y
And then highlight something with the mouse and press Control-C to copy it.
This feature only works when Vim has been compiled with the +xterm_clipboard option. Run vim --version to find out if it has.
Instead of set mouse=a use set mouse=r in .vimrc
On OSX use fn instead of shift.
In Ubuntu, it is possible to use the X-Term copy & paste bindings inside VIM (Ctrl-Shift-C & Ctrl-Shift-V) on text that has been hilighted using the Shift key.
Another OSX-Mac option is to uncheck View->Allow Mouse Reporting (or press ⌘-R to toggle it.) This allows you to toggle between mouse interaction and mouse selecting, which might be useful when selecting and copy/pasting a few bits because you don't have to hold a modifier key to do it.
Note for Multiline with line numbers:
I usually have line numbers enabled so this will also copy the line numbers if you select multiple lines. If you want to copy multiple lines without the line numbers disable the numbers with :set nonu and then you can :set nu to re-enable them after you're done copying.
Holding shift while copying and pasting with selection worked for me
You can use :set mouse& in the vim command line to enable copy/paste of text selected using the mouse. You can then simply use the middle mouse button or shiftinsert to paste it.
I accidently explained how to switch off set mouse=a, when I reread the question and found out that the OP did not want to switch it off in the first place. Anyway for anyone searching how to switch off the mouse (set mouse=) centrally, I leave a reference to my answer here: https://unix.stackexchange.com/a/506723/194822
Compilation settings that vim was compiled with, are part of the issue. vim --version shows these.
In OSX, the default vim has -clipboard But you need +clipboard
On osx you can and apparently generally should, use macvim. You can do brew cask install macvim That one has +clipboard.
Them you'll have two vims.
~$ ls -l /usr/bin/vim <--- default vim
-rwxr-xr-x 1 root wheel 1745984 15 Jul 2017 /usr/bin/vim
~$ ls -l /usr/local/bin/vim <-- macvim, installed recently via that mentioned brew line.
lrwxr-xr-x 1 apple admin 42 16 May 23:32 /usr/local/bin/vim -> /Applications/MacVim.app/Contents/bin/mvim
~$
running vim will run macvim 'cos /usr/local/bin should be before /usr/bin in the path, though you can check with which vim.
running vim(to run macvim), is fine but you may want to map vi to macvim 'cos otherwise running vi stays at the default vim! You can rewrite or delete(with rm) and recreate the vi sym link, with ln. And to do that without an 'operation not permitted" error, you have to (temporarily) disable SIL. https://apple.stackexchange.com/questions/208478/how-do-i-disable-system-integrity-protection-sip-aka-rootless-on-macos-os-x .
macvim has +clipboard as shown by vim --version
Here is a working ~/.vim/vimrc with just the required lines.
:set mouse=a
:map <leader>c "+y
:map <leader>v "+p
The default leader key is backslash.
I read a suggestion that one should use the leader key.. (certainly control has many keys already in use, so the suggestion was to not use control. I don't know if that applies to command key too, but anyhow).
With that mentioned mapping, \c will do "+y which will copy from the register known as +, to the clipboard. And \v will paste from the register known as +.
So that's a copy/paste that works between windows.
Another OS may require "* rather than "+
Add set clipboard=unnamed to your .vimrc. So it will use the clipboard register '*' instead of the unnamed register for all yank, delete, change and put operations (note it does not only affect the mouse).
The behavior of register '*' depends on your platform and how your vim has been compiled (or if you use neovim).
If it does not work, you can try with set clipboard=unnamedplus, but this option only makes sense on X11 systems (and gvim therefore).
If you are using, Putty session, then it automatically copies selection.
If we have used "set mouse=a" option in vim, selecting using Shift+Mouse drag selects the text automatically.
Need to check in X-term.
em...
Keep pressing Shift and then click the right mouse button
Also worth mentioning, by having set mouse=nvi, when doing a selection and then pressing : <ESC> you will get the mouse selection copied to the primary selection clipboard (equivalent to a "*y).
Reference: help mouse
Main advantage of this method is the fact that if you have multiple vertical splits, it will only select from the current buffer. Using <Shift> as mentioned in the main answer, will, in this case, copy from all 3 files at the same time which is not exactly what one would want, expect or need.
A good workaround which is worth adding:
GPM daemon can be used which is a a cut and paste utility and mouse server for virtual consoles. It will provide functionalities across all the virtual consoles!
Copy-Paste actions can be done by <CTRL-C>/<CTRL-V>.
sudo apt-get install gpm
MAN pages of GPM
set set mouse=a in vi, using MobaXterm, after installing vim-gtk3 on server, dragging with mouse and Ctrl + Insert works, but seems it only work with MobaXterm
after installing vim-gtk3, vi will link to it
lala#kubu:~$ sudo apt install gvim
[sudo] password for lala:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package gvim is a virtual package provided by:
vim-gtk3 2:8.2.2434-3ubuntu3.2
vim-athena 2:8.2.2434-3ubuntu3.2
You should explicitly select one to install.
E: Package 'gvim' has no installation candidate
lala#kubu:~$ which vi
/usr/bin/vi
lala#kubu:~$ file /usr/bin/vi
/usr/bin/vi: symbolic link to /etc/alternatives/vi
lala#kubu:~$ file /etc/alternatives/vi
/etc/alternatives/vi: symbolic link to /usr/bin/vim.gtk3
lala#kubu:~$
In ESC mode, when set mouse=a, select the text using mouse. This would enable the visual mode in vim. Then you can press 'y' to yank the selected text and 'p' to paste it wherever you want. This happens only within vim.

vim -- copy to system clipboard in OpenSuSE

I've tried the methods mentioned at Vim: copy selection to OS X clipboard, but neither the * or + register seem to be working for me. I'm on OpenSuSE 11.3, and have vim and vim-data installed (there is no vim-full package as mentioned in the link in SuSE). I've tried with Klipper enabled and disabled. (edit) I've also tried pasting with ctrl+v and middle click.
Thanks in advance.
See if you have something called vimx, an X enabled version of vim. You can alias vim to that, and then use * register.
This is a superuser question.
I presume that you are running VIM in terminal and talk about VIM's visual selection, not selection with the mouse in terminal window.
Since in your case VIM isn't aware of the X, it obviously cannot communicate your selection to the X Window System. If you select something in terminal window with mouse, then you are selecting not in VIM, but in the terminal emulator which is aware of the X and communicates properly the current selection to X's clipboard.
You can try to play around with xsel tool which allows one to access the X clipboard from command line. You would need to override the usual clipboard shortcuts to not only put the content of the visual selection into the usual VIM register(s), but also to pipe it to the xsel so that it becomes the new X selection. (Strangely enough, I do not have the xsel installed on the SLES10 system I have right now at hand.) That obviously would only work if (1) the terminal is running locally or (2) remote server you are connected to allows the X forwarding. If the X forwarding is disabled on the server where you edit the files, then you have no chance to do in VIM: only selecting with mouse in terminal window would work.
Check synchronize contents of the clipboard and the selection in the clipper configuration.
Highlight text with the mouse (will not work with vim key selections).
Your selection is in the clipper.

Resources