Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I have cmd + c work in neovim in iTerm on macOS? #5052

Closed
nikitavoloboev opened this Issue Jul 12, 2016 · 20 comments

Comments

Projects
None yet
5 participants
@nikitavoloboev
Copy link

nikitavoloboev commented Jul 12, 2016

  • nvim --version: 0.1.4
  • Operating system/version: macOS ver. 10.11.5
  • Terminal name/version: iTerm v. 3.0.4

Actual behaviour

When I select text and press cmd + c, it does not copy text to the system clipboard. Can I make this work? I know I can use 'y' to copy text and that works, however I have certain functions like 'search selected text in google' that require me to use cmd + c to copy the text. Is it possible to make this work?

Expected behaviour

I select text, press cmd + c and the text gets copied to my clipboard.

Thank you for any help on this.

@mhinz

This comment has been minimized.

Copy link
Member

mhinz commented Jul 12, 2016

Opposed to Vim, Neovim uses mouse=a by default. That means Vim uses the mouse for its own visual selections, so that iTerm won't even see them.

Either put set mouse= in your init.vim, or hold alt while making the selection. See :h 'mouse' for more information.

@mhinz mhinz closed this Jul 12, 2016

@nikitavoloboev

This comment has been minimized.

Copy link
Author

nikitavoloboev commented Jul 12, 2016

I have tried putting 'set mouse=' in my init.vim but this does not work. It still does not save my selection to the clipboard.

And I have the appropriate settings in iTerm too I believe :

2016-07-12 at 11 51

So in theory everything should work, but it doesn't :(

Here is my init.vim, perhaps it has something that makes a conflict for this to not happen.

@mhinz

This comment has been minimized.

Copy link
Member

mhinz commented Jul 12, 2016

I use the same iTerm settings. What's the output of :verb set mouse??

@nikitavoloboev

This comment has been minimized.

Copy link
Author

nikitavoloboev commented Jul 12, 2016

Here is what I get when I type the command :

2016-07-12 at 12 04

After pressing enter, it just goes away.

@mhinz

This comment has been minimized.

Copy link
Member

mhinz commented Jul 12, 2016

Hmm.. When you say "select text", you mean using the mouse, right?

@nikitavoloboev

This comment has been minimized.

Copy link
Author

nikitavoloboev commented Jul 12, 2016

Just normal text selection with 'visual mode'. But selecting text with the mouse doesn't work as well. It selects the text, but pressing cmd + c on it, does not copy it to my clipboard.

@mhinz

This comment has been minimized.

Copy link
Member

mhinz commented Jul 12, 2016

Well, it doesn't work like that. :) It's not possible in Vim either.

If you select something in Vim (that is with v and friends or with the mouse while mouse=a), iTerm never sees that selection, so cmd+c won't work either.

If you really need to use cmd+c, you have to use the mouse for selecting and set mouse=. I suggest fixing your script to use the output of pbpaste instead.

@nikitavoloboev

This comment has been minimized.

Copy link
Author

nikitavoloboev commented Jul 12, 2016

I see. Well I just need it to have my dash selection and google selection working. That is I select text, press a hotkey and it will search documentation or google. I also want to add snippets to typinator from selection and all that require the use of cmd + c.

I am not sure what I should modify to have it working. I really want this to work and I want to have it work without me having to select text with the mouse. So is there any way for iTerm to see and trigger cmd + c properly while I select text with v and friends? :(

Thank you for your help.

@justinmk

This comment has been minimized.

Copy link
Member

justinmk commented Jul 12, 2016

Use clipboard=unnamed

@nikitavoloboev

This comment has been minimized.

Copy link
Author

nikitavoloboev commented Jul 12, 2016

I have the line 'set clipboard=unnamed' in my init.vim already. This only allows me to have the text I copy with 'y' to be brought to system clipboard but I still cannot use cmd + c. Is that the command you meant?

@justinmk

This comment has been minimized.

Copy link
Member

justinmk commented Jul 12, 2016

Ok, yes. You could setup iterm to send a unique sequence when cmd C is pressed. Then you could map that sequence in n/vim.

@nikitavoloboev

This comment has been minimized.

Copy link
Author

nikitavoloboev commented Jul 12, 2016

hey justinmk,

I am very new to nevim and vim and I am really not sure how I can do such a thing. How would I setup my iTerm in this way?

Thank you a lot for your help.

@chemzqm

This comment has been minimized.

Copy link
Contributor

chemzqm commented Jul 12, 2016

@nikitavoloboev
screen shot 2016-07-12 at 11 19 15 pm
and you can remap +c to save content to clipboard like:

  vnoremap <M-c> "+y
@nikitavoloboev

This comment has been minimized.

Copy link
Author

nikitavoloboev commented Jul 12, 2016

@chemzqm

This seems to nearly work. However there are two issues :

  1. Now for some reason, when I try to open anything with nevim now, it says that 'No mapping is found' like so :

2016-07-12 at 19 20

  1. Now cmd + c seems to cut the text rather than copy.

What should I do to correct these issues. Also I am not really sure why this works. Now when I press command + c, it sends and escape sequence?

Thank you for your help.

@justinmk

This comment has been minimized.

Copy link
Member

justinmk commented Jul 12, 2016

@nikitavoloboev Need you to share your precise configuration. Preferably by reproducing it using nvim -u NORC (not your entire init.vim).

@nikitavoloboev

This comment has been minimized.

Copy link
Author

nikitavoloboev commented Jul 12, 2016

@justinmk
the command nvim -u NORC just opens a new nvim window.

I am not sure how I can share my precise configuration with you.

I am just using iTerm and for nevim, everything that is 'mine' is in my init.vim if I am not mistaken.

@justinmk

This comment has been minimized.

Copy link
Member

justinmk commented Jul 12, 2016

My comment was a bit confusing. anyways, I guess just post your init.vim somewhere

@chemzqm

This comment has been minimized.

Copy link
Contributor

chemzqm commented Jul 12, 2016

@nikitavoloboev I've corrected the mapping, try typing :vnoremap <M-c> "+y and use option + c to check if selected content copied to your system clipboard.

@nikitavoloboev

This comment has been minimized.

Copy link
Author

nikitavoloboev commented Jul 12, 2016

@justinmk

Here is my init.vim.

@chemzqm

I am not really sure how does the mapping work as +y is commented out for me due to " being a comment :

2016-07-12 at 23 09

I tried putting it and trying out option + c and it does not work. Also I want to have cmd + c working for that if I can and not option + c.

@ahuigo

This comment has been minimized.

Copy link

ahuigo commented May 23, 2018

We could make iterm2 send Esc+<multi-chars>

" config iTerm2 keys: Esc+Ac, Esc+As, Esc+Aa
vnoremap <M-A>c "+y
nnoremap <M-A>s :up<CR>
inoremap <M-A>s <C-o>:up<CR>
nnoremap <M-A>a ggVG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.