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

y does not yank to clipboard #17

Closed
lf94 opened this issue Jan 11, 2016 · 12 comments · Fixed by #260
Closed

y does not yank to clipboard #17

lf94 opened this issue Jan 11, 2016 · 12 comments · Fixed by #260
Labels

Comments

@lf94
Copy link

lf94 commented Jan 11, 2016

So now that we've got Ctrl+C, I need a way to copy+paste text between VS:C and other applications. Selection/highlighting only lets me copy 1 line (I'm not sure if this is amVim's fault or VS:C). Pressing y just yanks to some internal clipboard.

Normally in gvim, I would just use selection and middle-click to paste to other applications. Being able to yank to clipboard though would be very useful. I'm just not sure how possible or difficult that is with the underlying technologies.

@aioutecism
Copy link
Owner

VSCode's API only allows copy selections to system clipboard now.
I can let y to make a selection then copy to clipboard, but this will make selections "blink".

Instead, I'd recommend you create a custom map to call the built-in copy command.
This can be done by:

  1. Open command palette.
  2. Search for Preferences: Open Keyboard Shortcuts.
  3. Create a new map with your favorite key and command editor.action.clipboardCopyAction.

@lf94
Copy link
Author

lf94 commented Jan 12, 2016

Is the selections blinking just a UI effect? Maybe we can get the VSCode guys to add a user setting to turn it off?

@aioutecism
Copy link
Owner

Instead of turn the effect off, it would be better if they let extensions access system clipboard.

@ghost
Copy link

ghost commented Feb 3, 2016

Vim uses the + register to do this. "+y and "+p to copy and paste.

If we support that, we'll need to have some notion of registers, which doesn't exist right now.

@jcrben
Copy link

jcrben commented Jul 8, 2018

Cross-referencing another clipboard issue: #166

@karlhorky
Copy link
Contributor

it would be better if they let extensions access system clipboard

I guess VS Code has this ability, since VSCodeVim has this option to use the system clipboard...

Not sure exactly where it is in the codebase, but there are a few references that appear with a search:

https://github.com/VSCodeVim/Vim/search?q=system+clipboard&unscoped_q=system+clipboard

@karlhorky
Copy link
Contributor

karlhorky commented Aug 17, 2019

So I've found some keybindings that seem to work here! 🥳

  // Yank (copy) to system clipboard in VISUAL and VISUAL_LINE modes
  {
    "key": "y",
    "command": "editor.action.clipboardCopyAction",
    "when": "editorTextFocus && amVim.mode == 'VISUAL' && !inDebugRepl &&!suggestWidgetMultipleSuggestions && !suggestWidgetVisible"
  },
  {
    "key": "y",
    "command": "editor.action.clipboardCopyAction",
    "when": "editorTextFocus && amVim.mode == 'VISUAL LINE' && !inDebugRepl &&!suggestWidgetMultipleSuggestions && !suggestWidgetVisible"
  },
  {
    "key": "y y",
    "command": "editor.action.clipboardCopyAction",
    "when": "editorTextFocus && amVim.mode == 'NORMAL' && !inDebugRepl &&!suggestWidgetMultipleSuggestions && !suggestWidgetVisible"
  },
  // Delete (cut) to system clipboard in VISUAL modes
  {
    "key": "d",
    "command": "editor.action.clipboardCopyAction",
    "when": "editorTextFocus && amVim.mode == 'VISUAL' && !inDebugRepl &&!suggestWidgetMultipleSuggestions && !suggestWidgetVisible"
  },

Caveats

  • The active selection from the VISUAL modes stays with the yank keybindings

I'm also uncertain why I don't need to match for VISUAL LINE mode with the d keybinding - it just works in both modes. Maybe more mode bugginess?


There is one more binding that I originally wrote to paste from system clipboard in NORMAL mode, but it pastes even in INSERT mode 😳 (I guess there's some issue with the modes):

  // Paste from system clipboard only in NORMAL mode (not working - pastes also in INSERT mode)
  {
    "key": "p",
    "command": "editor.action.clipboardPasteAction",
    "when": "editorTextFocus && amVim.mode == 'NORMAL' && !inDebugRepl &&!suggestWidgetMultipleSuggestions && !suggestWidgetVisible"
  },

@aioutecism can you comment on why the mode check is not working here? I tried looking through the code, but I'm really lost there...

@karlhorky
Copy link
Contributor

I can let y to make a selection then copy to clipboard, but this will make selections "blink".

@aioutecism Also - would you consider adding this and an option for turning on this mode? I think there must be also a way to do it without the blinking (VSCodeVim achieves this somehow), but even with the blinking, it would be better than no copy to system clipboard (and also better than my hotkeys workaround).

@karlhorky
Copy link
Contributor

Asked in #166 (#166 (comment)) about having some instructions about how to add this feature (as well as paste from system clipboard):

#166 (comment)

@aioutecism
Copy link
Owner

Answered #166 (comment)

@karlhorky
Copy link
Contributor

My first shot at a pull request up at #260.

@karlhorky
Copy link
Contributor

Done in master (#260 was merged)! Will be released soon.

#272 contains documentation of the option.

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

Successfully merging a pull request may close this issue.

4 participants