1

I'm trying to make the switch to VIM, but there's one feature I'm really lacking and that's the highlight copy - pasting. Additionally, I am really lost with the "p" and "y" commands, I can't seem to copy or paste anything properly. I've set "clipboard=unnamedplus" to use the OS clipboard. Can you give me some pointers, or possibly a solution to my problems. It'd be nice if I could Ctrl+C / Ctrl+V things and be able to copy highlighted text to my clipboard and paste from my clipboard.

Thanks in advance.

fristys
  • 56
  • 1
  • 6
  • 2
    http://stackoverflow.com/a/1220118/2856441 should solve a number of the issues you seem to be having. – Joe Kennedy Jul 26 '14 at 22:41
  • "Making the switch to Vim" is a decision you take *once* you are comfortable with it not before. "Making the switch" should be a consequence, not the goal, of of your learning. – romainl Jul 27 '14 at 07:43
  • Also read [Learning Vim in 2014 - Copy and paste the vim way](http://benmccormick.org/2014/07/28/learning-vim-in-2014-copy-and-paste-the-vim-way/) – spoorcc Jul 28 '14 at 13:51
  • Best practises depend on the OS. In Windows for example, I work only with the system clipboar (from Windows). I copy either by selecting text with mouse, then hitting `y` or the normal way (`3yy`, `y$`, `y/^2021`). For pasting, it's crucial to understand the difference between `p` and `P`. – steffen Jan 30 '21 at 13:32

2 Answers2

2

By default, Vim yanks text and stores it in the " register; after yanking, you can see it by typing the :reg command.

However, you can control which register you want to yank or paste. For example, "aY yanks/copies the current line into register a, "cp puts/pastes the content from register c.

In Vim you have more than one "clipboard", you can "copy" many things in different "clipboards" and choose the right one to paste from. It is Vim's great advantage, isn't it?

If you want to use ctrl-c to copy selected text to system clipboard, you could:

"easier copy/paste to/from clipboard
vnoremap <C-C> "+y
nnoremap <Leader>p "+P

But I wouldn't use C-V to paste, as it is already assigned to the blockwise selection feature.

Max
  • 1,054
  • 1
  • 12
  • 20
Kent
  • 189,393
  • 32
  • 233
  • 301
0

To correctly paste from outside of terminal (possibly multiple indented lines of code) into Vim, add this to your ~/.vimrc:

set pastetoggle=<F2>

Then press F2, go to insert mode (you should see -- INSERT (paste) --) and Ctrl+shift+v to paste. Then again F2 to quit insert mode.

estranged
  • 424
  • 5
  • 16