Supo
Supo

Reputation: 1245

Intellij IDEA with ideavim. Cannot copy text from another source

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?

Upvotes: 117

Views: 49703

Answers (6)

alexanderbird
alexanderbird

Reputation: 4198

If you want everything to work like it used to but Ctrl+V in insert mode should paste from the clipboard, you can add the following insert remap in your ideavimrc:

" Let Ctrl+V paste from clipboard in insert mode
inoremap <C-V> <Esc>"*pa

Explanation

  • inoremap -- see https://stackoverflow.com/a/3776182/3012550
  • <C-V> map from Ctrl+V
  • <Esc>"*pa map to ...
    • <Esc> to exit insert mode
    • "*p to paste from the system clipboard
    • a to go back into insert mode after our newly pasted text

(Note that you'll need to run :so $MYVIMRC to reload the vimrc before the change takes effect.)

Upvotes: 0

Bob
Bob

Reputation: 1075

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

Upvotes: 7

Alwin
Alwin

Reputation: 11

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.

Upvotes: 1

mmey
mmey

Reputation: 1685

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)

Upvotes: 4

OuttaSpaceTime
OuttaSpaceTime

Reputation: 966

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

Upvotes: 6

jbyler
jbyler

Reputation: 7847

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.

Upvotes: 224

Related Questions