system copy with command-C without moving cursor

Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

system copy with command-C without moving cursor

Steve Molin
I would like to use double-click to select a word and command-C to copy to the system cut buffer (terminology?), which works fine as long as "set mouse=a"

But that has the side effect of moving the insert cursor position, which I disable with "set mouse="

Can I have both behaviors? Ie, double-click to select a work, command-C to copy selection, without moving the cursor?

I've ready extensively in the FAQ and other docs and I can't figure it out.

Thanks!

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/fe3ffa5f-20ac-4adb-80d4-480b1ad56fa4%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: system copy with command-C without moving cursor

Tony Mechelynck
On Wednesday, November 6, 2019 at 11:32:09 PM UTC+1, Steve Molin wrote:
I would like to use double-click to select a word and command-C to copy to the system cut buffer (terminology?), which works fine as long as "set mouse=a"

But that has the side effect of moving the insert cursor position, which I disable with "set mouse="

Can I have both behaviors? Ie, double-click to select a work, command-C to copy selection, without moving the cursor?

I've ready extensively in the FAQ and other docs and I can't figure it out.

Thanks!

The canonical way to put stuff into the clipboard or the cut-buffer in Vim is to "yank" (or "delete") into either register + or register *. Under X11 (Unix, Linux, BeOS, etc.) these two registers are different, under Windows they are the same, under OSX I'm not sure. Register + (the "clipboard") is used in all GUIs (including gvim) for Edit→Copy, Edit→Paste and Edit→Cut. Register * (the "selection") is pasted by the middle mouse button.

The mouse works beautifully in gvim (or, I suppose, in the macvim GUI); when running Vim in a terminal it depends on the terminal. If the mouse doesn't do what you want you can always use the keyboard: for instance, to yank the current word into the clipboard from Insert mode it's Ctrl-O (or maybe Cmd-O on OSX, I'm not sure but I don't think so) followed by "+yaw (Ctrl-O for "do one Normal-mode command", quote-plus for "into the clipboard" and yaw for "yank a word). Once you get the hang of it you'll find out that the mouse is ideal to move the cursor to a random point in the text and that the keyboard is more efficient for almost everything else.

Best regards,
Tony.

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/c8bceed2-ae21-42a7-b6ee-5a946f8fdca1%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: system copy with command-C without moving cursor

Steve Molin
Thank you for your reply, Tony. I didn't mean to imply that the mouse doesn't work beautifully, it does and I'm constantly amazed by the power of Vim.

Having tinkered with this for a couple hours, and read what I can find in the manual, I think the problem is that when 'set mouse=' there are two different things that can be called the "selection": you can select using the Vim commands (eg vw) or using the mouse (eg double-left-click). When you hit command-C MacVim will copy the Vim-command-selection to the system clipboard but not the mouse-selection (presumably the same with gvim and control-C in Windows and X)

I tried unmapping command-C, hoping that would let the system process it, but MacVim still processes it (eg in insert, control-v command-c then results in the text "<D-c>")

p.s. For completeness, I tested with no .vimrc with the same results.

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/6d7677cc-d6f0-44e8-8009-3e6092ebb7bf%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: system copy with command-C without moving cursor

Tony Mechelynck
On Friday, November 8, 2019 at 5:51:31 PM UTC+1, Steve Molin wrote:
Thank you for your reply, Tony. I didn't mean to imply that the mouse doesn't work beautifully, it does and I'm constantly amazed by the power of Vim.

Having tinkered with this for a couple hours, and read what I can find in the manual, I think the problem is that when 'set mouse=' there are two different things that can be called the "selection": you can select using the Vim commands (eg vw) or using the mouse (eg double-left-click). When you hit command-C MacVim will copy the Vim-command-selection to the system clipboard but not the mouse-selection (presumably the same with gvim and control-C in Windows and X)

I tried unmapping command-C, hoping that would let the system process it, but MacVim still processes it (eg in insert, control-v command-c then results in the text "<D-c>")

p.s. For completeness, I tested with no .vimrc with the same results.

Hm, it seems I'm out of my depth here, you'll probably need some Mac user to help you (I'm on Linux).

Best regards,
Tony.

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/c0b497cb-8083-4afa-8fbe-149a9c324e91%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: system copy with command-C without moving cursor

Yee Cheng Chin-2
MacVim maintainer here. I think what you are looking for is similar to how Vim running in a terminal has two tiers of selection / copy-paste: Vim's own visual mode selection and yanking, versus terminal's (or tmux) own selection and copy-paste mechanism. For example, in most terminals you can hold down shift key and select using mouse to use the terminal's own selection scheme rather than Vim's (even with mouse=a). In fact, Vim's default interactions with the hosting terminal's copy-and-paste has been a source of contention and why Vim just changed defaults from mouse=a to mouse=nvi.

Vim GUIs *kind of* have a concept of the same "system/terminal copy-paste" outside of visual mose / yanking that you want, but it's a little half-baked. Look up ":h modeless-selection" to read more. If you do "set mouse=" and then select texts in the GUI you are using modeless selection, which kind of simulates an external text selection. Annoyingly, you have to be in command line mode in order to copy texts (using CTRL-Y), so you have to type ":" to enter command-line mode first before you can copy the text. (Again, read the docs which provides more details)

For the MacVim-specific part of not being able to unmap Cmd-C, that's because it's registered in the system for the Edit -> Copy menu item, so macOS will hijack it first. You can either remap the hotkey to something else (see ":h macmenu") or just remove the menu item (":aunmenu Edit.Copy").

So the tldr is, do the following, and you will be able to use Cmd-C to copy texts when you have "set mouse=":

aunmenu Edit.Copy
nnoremap <D-c> :<C-Y><Esc>

Hope that helps!

On Sat, Nov 9, 2019 at 1:37 AM Tony Mechelynck <[hidden email]> wrote:
On Friday, November 8, 2019 at 5:51:31 PM UTC+1, Steve Molin wrote:
Thank you for your reply, Tony. I didn't mean to imply that the mouse doesn't work beautifully, it does and I'm constantly amazed by the power of Vim.

Having tinkered with this for a couple hours, and read what I can find in the manual, I think the problem is that when 'set mouse=' there are two different things that can be called the "selection": you can select using the Vim commands (eg vw) or using the mouse (eg double-left-click). When you hit command-C MacVim will copy the Vim-command-selection to the system clipboard but not the mouse-selection (presumably the same with gvim and control-C in Windows and X)

I tried unmapping command-C, hoping that would let the system process it, but MacVim still processes it (eg in insert, control-v command-c then results in the text "<D-c>")

p.s. For completeness, I tested with no .vimrc with the same results.

Hm, it seems I'm out of my depth here, you'll probably need some Mac user to help you (I'm on Linux).

Best regards,
Tony.

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/c0b497cb-8083-4afa-8fbe-149a9c324e91%40googlegroups.com.

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/CAHTeOx_EW8P364SNPFyw4bdkhPbXYyWdexVP0PydPNYga5giow%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: system copy with command-C without moving cursor

Steve Molin
On Sun, Nov 10, 2019 at 12:35 AM Yee Cheng Chin <[hidden email]> wrote:

>
> MacVim maintainer here. I think what you are looking for is similar to how Vim running in a terminal has two tiers of selection / copy-paste: Vim's own visual mode selection and yanking, versus terminal's (or tmux) own selection and copy-paste mechanism. For example, in most terminals you can hold down shift key and select using mouse to use the terminal's own selection scheme rather than Vim's (even with mouse=a). In fact, Vim's default interactions with the hosting terminal's copy-and-paste has been a source of contention and why Vim just changed defaults from mouse=a to mouse=nvi.
>
> Vim GUIs *kind of* have a concept of the same "system/terminal copy-paste" outside of visual mose / yanking that you want, but it's a little half-baked. Look up ":h modeless-selection" to read more. If you do "set mouse=" and then select texts in the GUI you are using modeless selection, which kind of simulates an external text selection. Annoyingly, you have to be in command line mode in order to copy texts (using CTRL-Y), so you have to type ":" to enter command-line mode first before you can copy the text. (Again, read the docs which provides more details)
>
> For the MacVim-specific part of not being able to unmap Cmd-C, that's because it's registered in the system for the Edit -> Copy menu item, so macOS will hijack it first. You can either remap the hotkey to something else (see ":h macmenu") or just remove the menu item (":aunmenu Edit.Copy").
>
> So the tldr is, do the following, and you will be able to use Cmd-C to copy texts when you have "set mouse=":
>
> aunmenu Edit.Copy
>
> nnoremap <D-c> :<C-Y><Esc>
>
>
> Hope that helps!


Thank you very much for this information! It was very helpful. I tried
to get it to work from insert mode with "inoremap <D-c>
<C-o>:<C-Y><Esc>" but no luck, so I've settled on the "autocopy"
mechanism. So I now have

set mouse=
set guioptions+=A

and I'll try it for a while to see if it's "good enough".

Thanks again for your help, and also for your work on MacVIm!

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/CAK-YbyCS2ipM_h%2BR03VWPpu%3D1kdoWSmfdgk%2BQ-V3xh%2BN4Nyoxg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: system copy with command-C without moving cursor

Yee Cheng Chin-2
The insert mode mapping should work so I'm not sure why it's not working for you. It could be that you didn't do "aunmenu Edit.Copy" as I described (you would be able to tell if that's the case because you will see the "Edit" menu flash briefly).

Also, thinking more about it I think advising you to unmap Edit.Copy was unwise. You could just remap the "Edit.Copy" menu to do the right thing for you. Just do the following and Cmd-C should work as expected. This makes the existing mappings work, and after the next MacVim release, Edit.Copy / Cmd-C will be able to copy from Vim terminals out-of-the-box as well.

Basically, just add these to your vimrc instead of manually mapping <D-c>:

nnoremenu Edit.Copy :<C-Y><Esc>
inoremenu Edit.Copy <C-O>:<C-Y><Esc>

On Tue, Nov 12, 2019 at 12:28 PM Steve Molin <[hidden email]> wrote:
On Sun, Nov 10, 2019 at 12:35 AM Yee Cheng Chin <[hidden email]> wrote:
>
> MacVim maintainer here. I think what you are looking for is similar to how Vim running in a terminal has two tiers of selection / copy-paste: Vim's own visual mode selection and yanking, versus terminal's (or tmux) own selection and copy-paste mechanism. For example, in most terminals you can hold down shift key and select using mouse to use the terminal's own selection scheme rather than Vim's (even with mouse=a). In fact, Vim's default interactions with the hosting terminal's copy-and-paste has been a source of contention and why Vim just changed defaults from mouse=a to mouse=nvi.
>
> Vim GUIs *kind of* have a concept of the same "system/terminal copy-paste" outside of visual mose / yanking that you want, but it's a little half-baked. Look up ":h modeless-selection" to read more. If you do "set mouse=" and then select texts in the GUI you are using modeless selection, which kind of simulates an external text selection. Annoyingly, you have to be in command line mode in order to copy texts (using CTRL-Y), so you have to type ":" to enter command-line mode first before you can copy the text. (Again, read the docs which provides more details)
>
> For the MacVim-specific part of not being able to unmap Cmd-C, that's because it's registered in the system for the Edit -> Copy menu item, so macOS will hijack it first. You can either remap the hotkey to something else (see ":h macmenu") or just remove the menu item (":aunmenu Edit.Copy").
>
> So the tldr is, do the following, and you will be able to use Cmd-C to copy texts when you have "set mouse=":
>
> aunmenu Edit.Copy
>
> nnoremap <D-c> :<C-Y><Esc>
>
>
> Hope that helps!


Thank you very much for this information! It was very helpful. I tried
to get it to work from insert mode with "inoremap <D-c>
<C-o>:<C-Y><Esc>" but no luck, so I've settled on the "autocopy"
mechanism. So I now have

set mouse=
set guioptions+=A

and I'll try it for a while to see if it's "good enough".

Thanks again for your help, and also for your work on MacVIm!

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/CAK-YbyCS2ipM_h%2BR03VWPpu%3D1kdoWSmfdgk%2BQ-V3xh%2BN4Nyoxg%40mail.gmail.com.

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/CAHTeOx-C3pUZMQ1DVmbXMThf6ErJce6aLxqve7HzmWjWwoRNRQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: system copy with command-C without moving cursor

Steve Molin
With 'set mouse=' this works perfectly for me, thank you!! MacVim is
great, thanks again, looking forward to future releases.

On Wed, Nov 13, 2019 at 11:49 PM Yee Cheng Chin <[hidden email]> wrote:

>
> The insert mode mapping should work so I'm not sure why it's not working for you. It could be that you didn't do "aunmenu Edit.Copy" as I described (you would be able to tell if that's the case because you will see the "Edit" menu flash briefly).
>
> Also, thinking more about it I think advising you to unmap Edit.Copy was unwise. You could just remap the "Edit.Copy" menu to do the right thing for you. Just do the following and Cmd-C should work as expected. This makes the existing mappings work, and after the next MacVim release, Edit.Copy / Cmd-C will be able to copy from Vim terminals out-of-the-box as well.
>
> Basically, just add these to your vimrc instead of manually mapping <D-c>:
>
> nnoremenu Edit.Copy :<C-Y><Esc>
>
> inoremenu Edit.Copy <C-O>:<C-Y><Esc>
>
>
> On Tue, Nov 12, 2019 at 12:28 PM Steve Molin <[hidden email]> wrote:
>>
>> On Sun, Nov 10, 2019 at 12:35 AM Yee Cheng Chin <[hidden email]> wrote:
>> >
>> > MacVim maintainer here. I think what you are looking for is similar to how Vim running in a terminal has two tiers of selection / copy-paste: Vim's own visual mode selection and yanking, versus terminal's (or tmux) own selection and copy-paste mechanism. For example, in most terminals you can hold down shift key and select using mouse to use the terminal's own selection scheme rather than Vim's (even with mouse=a). In fact, Vim's default interactions with the hosting terminal's copy-and-paste has been a source of contention and why Vim just changed defaults from mouse=a to mouse=nvi.
>> >
>> > Vim GUIs *kind of* have a concept of the same "system/terminal copy-paste" outside of visual mose / yanking that you want, but it's a little half-baked. Look up ":h modeless-selection" to read more. If you do "set mouse=" and then select texts in the GUI you are using modeless selection, which kind of simulates an external text selection. Annoyingly, you have to be in command line mode in order to copy texts (using CTRL-Y), so you have to type ":" to enter command-line mode first before you can copy the text. (Again, read the docs which provides more details)
>> >
>> > For the MacVim-specific part of not being able to unmap Cmd-C, that's because it's registered in the system for the Edit -> Copy menu item, so macOS will hijack it first. You can either remap the hotkey to something else (see ":h macmenu") or just remove the menu item (":aunmenu Edit.Copy").
>> >
>> > So the tldr is, do the following, and you will be able to use Cmd-C to copy texts when you have "set mouse=":
>> >
>> > aunmenu Edit.Copy
>> >
>> > nnoremap <D-c> :<C-Y><Esc>
>> >
>> >
>> > Hope that helps!
>>
>>
>> Thank you very much for this information! It was very helpful. I tried
>> to get it to work from insert mode with "inoremap <D-c>
>> <C-o>:<C-Y><Esc>" but no luck, so I've settled on the "autocopy"
>> mechanism. So I now have
>>
>> set mouse=
>> set guioptions+=A
>>
>> and I'll try it for a while to see if it's "good enough".
>>
>> Thanks again for your help, and also for your work on MacVIm!
>>
>> --
>> --
>> You received this message from the "vim_mac" maillist.
>> Do not top-post! Type your reply below the text you are replying to.
>> For more information, visit http://www.vim.org/maillist.php
>>
>> ---
>> You received this message because you are subscribed to the Google Groups "vim_mac" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
>> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/CAK-YbyCS2ipM_h%2BR03VWPpu%3D1kdoWSmfdgk%2BQ-V3xh%2BN4Nyoxg%40mail.gmail.com.
>
> --
> --
> You received this message from the "vim_mac" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to a topic in the Google Groups "vim_mac" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_mac/3dkCXMBe-o0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/CAHTeOx-C3pUZMQ1DVmbXMThf6ErJce6aLxqve7HzmWjWwoRNRQ%40mail.gmail.com.

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/CAK-YbyDzSNvRuRGYjOMPvsYe3XnHvkuJDovQQt3TxO1aCz8tBA%40mail.gmail.com.