0

In my .vimrc I have those two lines for copy and paste into the system clipboard:

nnoremap <Leader>p "+p
nnoremap <Leader>y "+y

Weirdly the remapping of pasting works fine, but I can't copy any lines. If I press the buttons "+y it works and the highlighted text is in my system clipboard, but if I use < Leader> y it is only copied into a register inside vim, but not into the system clipboard.

Some help would be great!

Natjo
  • 2,005
  • 29
  • 75

2 Answers2

2

If you use your mapping in Visual mode, you have to use vnoremap or noremap, instead of nnoremap (which is for Normal mode only).

See :h map-overview for details.

yolenoyer
  • 8,797
  • 2
  • 27
  • 61
  • Thanks, a quite obvious mistake, of course pasting works in normal mode, but if I highlight something I leave the normal mode. – Natjo Apr 11 '16 at 19:17
1

Your yanking mapping is incorrect. "+y lacks a motion. If you want to yank the whole line use upper Y ("+Y) or or yy ("+yy).

:help y
                        *y* *yank*
["x]y{motion}       Yank {motion} text [into register x].  When no
            characters are to be yanked (e.g., "y0" in column 1),
            this is an error when 'cpoptions' includes the 'E'
            flag.

Note that, if you type "+y, vim hangs in "operation-penging mode" (:help Operator-pending-mode).

Magnun Leno
  • 2,728
  • 20
  • 29
  • You are right, thanks for the answer, but for me it was most important to copy highlighted code. My mistake was quite obvious :) – Natjo Apr 11 '16 at 19:18
  • How to yank multilines(maybe 1, 2, 3,..., n lines)? such as we could use y2y, 3yy, y4y to copy 2, 3, 4 line to default register. – roachsinai Nov 02 '18 at 12:00