Intellij IDEA with ideavim. Cannot copy text from another source
Asked Answered
T

5

113

I tried to copy text from IDEA with ideavim plugin, using default vim keybindings (y). But this text isn't copied in global buffer and i can paste it only in IDEA.
How can I use copied piece of text in browser, for example?

Tamatamable answered 12/1, 2015 at 9:5 Comment(2)
Okay, i got it. In IDEA keymap settings for Copy action are set 2 combinations: Ctrl + c and Ctrl + Insert. I don't know why Ctrl + c isn't working, but now I use second one.Tamatamable
Ctrl+C isn't working because it is handled by Vim. You can change this behaviour in "Other Settings -> Vim Emulation" by setting 'Handler' to IDE.Lacerate
S
212

Vim's yank command doesn't yank to the system clipboard by default; it yanks to the unnamed register. You can use the * or + register to access the system clipboard; also see this wiki article for more information. Or just set this option in your ~/.ideavimrc:

set clipboard+=unnamed

This ~/.ideavimrc setting has been supported in IdeaVim since VIM-476 was implemented in version 0.38. If the file does not exist create it in your user/home directory.

Note also that this is all standard Vim behavior; none of it is specific to IdeaVim except for the name of the config file.

Surd answered 13/1, 2015 at 18:8 Comment(6)
set clipboard+=unnamed uses the * register, aka primary selection. If you prefer to use register +, aka clipboard, then ``set clipboard+=unnamedplus. You can also set these interactively from the :` prompt to experiment and see what works best for you.Novelty
If you are on Windows and are looking for .ideavimrc, then see https://mcmap.net/q/195762/-where-i-can-find-ideavimrc-file-of-ideavim-0-41-on-windows-7Inaccurate
On Windows will be C:\Users\YourUserName\.ideavimrcPudgy
If you're like me and can't remember the command to yank into a register, it's "+y with a selection in visual mode.Aleurone
you can find an interesting discussion here gist.github.com/RobertAudi/11ffa90f4952e5923ce7Chicoine
This will also copy deleted content into the clipboard. See my post below for an alternative if you don't want that to happen.Ferity
B
4

Another option is that you can go to the setting of the ideavim plugin and set ctrl + c and ctrl + v to be handled by the IDE and not by vim.

This will allow you to copy and paste as usual in the IDE and paste outside the IDE as well.

Note

when you set ctrl + v to be handled by the IDE ctrl + v for selection will not work in VIM. As an alternative you might just use ctrl + shift + v in IDE as default (works by default for paste with selection)

Steps

in your lower right corner select settings:

enter image description here

Then search for the shortcut and select the option IDE for handler.

enter image description here

Bazluke answered 2/8, 2022 at 11:13 Comment(1)
I've been using this solution https://mcmap.net/q/193523/-intellij-idea-with-ideavim-cannot-copy-text-from-another-source for a while, but I find this solution much better than using register. register copies everything also unnecessary lines that you are deleting, or you are yanking just for editing and that create confusion.Chicoine
F
4

The accepted answer will also copy deleted content to the system clipboard (using d, dd, ...), basically turning deletion into a "cut to clipboard" operation. If (like me), that's not what you want at all, you can add the following mappings to ~/.ideavimrc:

# Use system clipboard by default for y and p operations

nnoremap yy "+yy
vnoremap y "+y

nnoremap p "+p
vnoremap p "+p
nnoremap P "+P
vnoremap P "+P

# Allow access to original y and p operations with leader key, e.g. to use registers

nnoremap <leader>yy yy
vnoremap <leader>y y

nnoremap <leader>p p
vnoremap <leader>p p
nnoremap <leader>P P
vnoremap <leader>P P

# Allow to cut to system clipboard by using leader key with d

nnoremap <leader>dd "+dd
vnoremap <leader>d "+d

(courtesy of https://gist.github.com/RobertAudi/11ffa90f4952e5923ce7 and @albert-bici)

Ferity answered 22/9, 2023 at 9:41 Comment(4)
Just noticed that this will break registers, so I won't be able to copy stuff to register a with e.g. "a yy anymore - which is rater annoying...Ferity
you could also experiment with mappings for deleting to the black-hole register "_. For example maybe nnoremap d "_d and vnoremap d "_d would give you deletion to black-hole, so you can leave y and p mappings alone.Surd
Or just use a different mapping for the yank case. e.g. nnoremap zy "*y nnoremap zY "*Y vnoremap zy "*y vnoremap zY "*Y. Or instead of zy use <leader>y.Surd
Thanks @jbyler, I've enhanced my config file to contain alternatives with leader key.Ferity
T
1

I just discoverd that IdeaVim now has this setting "built-in." In the .ideavimrc file, put in set clipboard^=ideaput. Save and restart the IDE and it should now use the system clipboard.

Tuesday answered 5/11, 2023 at 23:11 Comment(0)
M
1

I found that unnamedplus has the best behaviour on Linux & Mac OS. It allows me to select words with IntelliJ, and yank, and paste over them, while still allowing system clipboard usage.

In your ~/.ideavimrc file, add:

set clipboard+=unnamedplus
Meehan answered 29/1, 2024 at 1:39 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.