5

Possible Duplicate:
vim: copy selection to OS X clipboard

While I succeeded to map paste from clipboard (nmap <leader>p "*p), the same for yank (nmap <leader>y "*y) doesn't seem working. Actually, it yanks in Vim's clipboard.

Any idea how to do it properly? I know of clipboard=unnamed but I might keep the old yank/paste vim's commands.

EDIT: It seems there is some confusion about my needs.

The command "*y works. So there is nothing wrong with the +clipboard thing in my Vim env. What does not work is the mapping stuff.

I want to add stuff like:

nmap <leader>y "*y # Doesn't work as expected. It copies only in Vim's clipboard, ie I have to type `p` to paste the copied content instead of `"*p`.
nmap <leader>p "*p # Works as expected.

Am I clearer?

2nd EDIT: Just in case, 'cause I have no idea what could help you helping me, there is the render of vim --version in my machine: https://gist.github.com/3090385

Community
  • 1
  • 1
Adrien
  • 2,088
  • 1
  • 18
  • 35
  • http://stackoverflow.com/a/679419/390913 – perreal Jul 10 '12 at 15:16
  • @perreal: `% vim --version | grep clipboard -clientserver **+clipboard** +cmdline_compl +cmdline_hist +cmdline_info +comments` @perreal, @GWW: The point is not how to yank/paste with OS's Clipboard. It works already. The point is how to map these commands. It's just the mapping whose wrong but IO don't know why… – Adrien Jul 10 '12 at 16:04
  • 1
    Check `:reg *` and `:reg "`. when you do `"*y` the content is always put into the default register *and* synced with the system clipboard via the `*` register. You should have the exact same content in both registers when you do `"*y`. – romainl Jul 10 '12 at 16:56
  • If you add `source $VIMRUNTIME/mswin.vim` to your .vimrc, then you can use standard Ctrl + C/V for copy/paste clipboard operations (+ Shift if you are running vim from console). Maybe this would fit you better. – MatijaSh Jul 11 '12 at 01:59
  • @romainl : You're right. I didn't know about that. I checked and directly using `"*y` puts the same content in both registers. But using the mapped command `,y`, where `,` is my ``, the only register impacted is `"`. And that's my problem. I don't understand what's wrong when I try to map these thing. Any idea? – Adrien Jul 11 '12 at 10:27
  • 1
    Using the exact same mapping as you (`:nmap y "*y`) I still — logically — end up with the same content in `"` and in `*`. The only way I'm able to have different content in these registers is to do `y` with `:set clipboard=`. Mapped or not, `"*y` always work the same expected way. Maybe it's conflicting with something else, try `:verbose nmap y` and `:verbose nmap y`. – romainl Jul 11 '12 at 12:40
  • `:verbose nmap y` gave me `n ,y "*yr>y`. Not sure to know what that means :'). `:verbose nmap y` gave me `No mapping found`. I tried `:verbose nmap p` and it gave me something similar `n ,p "*pr>p`. – Adrien Jul 11 '12 at 12:46
  • Guys… Stop voting up @GWW's comment. As I said it already, I do not want to use OS's clipboard by default. So it's nothing to do with the linked topic. – Adrien Jul 11 '12 at 13:27
  • 1
    If `"*y` works, but a mapping to `"*y` does not, then I would guess that you have some other mapping (perhaps in a plugin?) that is causing problems. I think you are on track with :verbose nmap. Maybe there is some kind of recursive mapping occurring? Look for mappings to substrings inside your map. And maybe try removing plugins until problem goes away or problem plugin is identified? You may want to look at `execute "normal!"` or `noremap`... – darcyparker Jul 11 '12 at 13:49
  • @darcyparker: Thanks! Indeed, `noremap` save my day finally. Although I have absolutely no idea what could interfere. By curiosity, how to * look for mappings to substrings inside my map*? I could come back with a more detailed answer even if your solution satisfies me :) – Adrien Jul 11 '12 at 15:26
  • 1
    @AdrienGiboire: Try this. `:redir @a`, then `:nmap` or `:verbose nmap`, and finally `:redir END`. Those steps basically redirect the output of nmap to the `a` register. Then create a new buffer, paste in the `a` register, and use `/` search to look for things like ", * and y to see if they were re-mapped in some cases. – darcyparker Jul 11 '12 at 18:42
  • @darcyparker: Thanks a lot! I learned a lot of things :) – Adrien Jul 12 '12 at 08:41

1 Answers1

6

If you're visually selecting before yanking then you need vmap not nmap. Otherwise, yank is a normal command and is expecting a motion command.

Conner
  • 30,144
  • 8
  • 52
  • 73