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

[vim] Ability to perform a copy #3075

Closed
DrPandemic opened this issue Feb 9, 2015 · 8 comments
Closed

[vim] Ability to perform a copy #3075

DrPandemic opened this issue Feb 9, 2015 · 8 comments
Labels

Comments

@DrPandemic
Copy link

Hi,
I'm trying to use the vim mode from CodeMirror and there is one thing bordering me. I'm aware that the command Ctrl-C is used in vim to return to the normal mode, but in a GUI based text editor, Ctrl-C would pretty much always be the copy. I know that most people using vim would want to keep the Ctrl-C to change mode, but I think it could be an option.
In the code the Ctrl-C is hardcoded (https://github.com/codemirror/CodeMirror/blob/f1692af532b78b7aeacb9dfc1962e2443866f65b/keymap/vim.js),

if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[') {

Wouldn't be nice to have an option to disable this?
What to you think guys? I would be really interested to know your opinion.

@mightyguava
Copy link
Contributor

That sounds like a very reasonable suggestion.

@mightyguava mightyguava added the vim label Feb 9, 2015
@crantok
Copy link

crantok commented Jun 17, 2015

Yes please.

Just started using Light Table. Searched to find out how to change ctrl-c to copy while in insert mode. This was the top hit on google.

@mightyguava
Copy link
Contributor

So looking back on this, Light Table has a solution for this LightTable/LightTable#688. Does this not work for you?

@crantok
Copy link

crantok commented Aug 3, 2015

Thank you. Works for me.

@marijnh
Copy link
Member

marijnh commented Sep 2, 2015

@Mange
Copy link

Mange commented Jan 25, 2018

I can't even copy at all. I have to disable Vim mode, copy with CTRL-C and then enable vim mode again.

  • Ctrl-C exits insert mode.
  • Yanking only places text in the " register. Not possible to paste in other programs.
  • Cannot yank to + or * registers as they are not implemented.
  • X11 Primary selection does not work either.
  • No right-click menu to choose "Copy" from.
  • Ctrl-P still works to paste, however. Weird.

This is from using GraphQL Playground, which is using CodeMirror inside an Electron app, on Linux.

IMO yanking to + should perform a normal copy to the system clipboard, no matter what people think about the Ctrl-C situation. That could be a first step.

@ianhi
Copy link
Contributor

ianhi commented Apr 11, 2020

So come 2020 the situation has evolved somewhat for the better. Firefox, Edge, Chrome and Opera now all support navigator.clipboard.writeText https://caniuse.com/#search=writeText
So yank can be modified to modified to push to the system clipboard on usage of the * or + registers by adding this:

  if (['+', '*'].indexOf(args.registerName) !== -1) {
    navigator.clipboard.writeText(text).catch(err => {
      // This can happen if the user denies clipboard permissions:
      // or if using safari
      console.error('Could not copy text: ', err);
    });
    cm.focus()
  }

to the yank function.

I think the two issues with this approach are:

  1. Doesn't work on Safari
  2. In nonsecure contexts (not https or localhost) this will request permission.

Even though Safari isn't supported maybe this could be added because it won't negatively impact Safari users?

As evidence that this works I patched this into jupyterlab's codemirror like this: https://github.com/ianhi/jupyterlab_vim-system-clipboard-support/blob/2ebc799500f9a44c7e7cb00f71a1a30112833277/src/yank.ts#L27

@marijnh
Copy link
Member

marijnh commented Jul 19, 2022

The vim code is now being maintained at https://github.com/replit/codemirror-vim/ . If this is still important, check whether there is an issue open for it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants