Support :set clipboard=unnamed from vimrc#9985
Open
digitalby wants to merge 2 commits intoVSCodeVim:masterfrom
Open
Support :set clipboard=unnamed from vimrc#9985digitalby wants to merge 2 commits intoVSCodeVim:masterfrom
digitalby wants to merge 2 commits intoVSCodeVim:masterfrom
Conversation
…c aliases the unnamed register
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
Adds support for Vim's
clipboardoption, so thatin a
.vimrc(or as an interactive:set clipboard=unnamed) aliases the unnamed register ("") to the system clipboard, matching real Vim's behavior. Until now, VSCodeVim only exposed the equivalent behavior through the VS Code settingvim.useSystemClipboard, and anyset clipboard=...line in a vimrc was silently dropped because the vimrc loader only processed key mappings, not:setlines.The change is built in two logical commits:
1.
refactor: extract :set parser and applier so non-interactive callers can reuse themSetOperationtype, option-alias lookup, and mutation logic out ofsrc/cmd_line/commands/set.tsinto a newsrc/cmd_line/commands/setOperation.tsthat takes anIConfigurationby parameter instead of reaching for the singleton.SetCommandbecomes a thin wrapper that still owns the interactiveshow/ status-bar path.optionAliasesinto its own file (src/configuration/optionAliases.ts), re-exported fromconfiguration.tsfor backward compatibility.configuration.ts) reuse the same parser + mutation path without reintroducing a circular dependency.2.
feat: support vim clipboard option …vim.clipboardtopackage.jsonwith enum["", "unnamed", "unnamedplus"], default"".clipboardfield toIConfiguration/Configuration, plus a smallclipboardAliasesUnnamedRegistergetter that returnstruewhen eitheruseSystemClipboardis on orclipboardis set tounnamed/unnamedplus.configuration.useSystemClipboardread sites (src/state/recordedState.ts,src/cmd_line/commands/put.ts,src/actions/commands/put.ts) with the new getter so both knobs converge on the same code path.VimrcImpl.loadConfig(src/configuration/vimrc.ts) to recognizeset …/se …lines and run them throughsetOperationParser+applyOperationToConfig. Parse failures and unknown options are logged viaLogger.warnper line, so one bad line can't abort the rest of the vimrc. As a side benefit, any other string/number/boolean option now also works from vimrc (set ignorecase,set scrolloff=8, etc.) for free.Both
unnamedandunnamedplusmap to the same behavior because VS Code exposes a single clipboard concept — there's no separatePRIMARYselection to bind to"*"vs"+". A comment in the getter notes this so a future contributor can split them if a platform ever grows that distinction.Which issue(s) this PR fixes:
None — opening directly.
Special notes for your reviewer:
applyOperationToConfig(config, op)with allconfiguration[option] = …assignments rewritten toconfig[option] = …. The interactiveshow/show_or_set-on-string branches still live inSetCommand.executebecause they need aVimStatefor the status bar.configuration.tsdynamically importsvimrc.ts, sovimrc.tscan't statically import anything that reachesconfiguration.ts. Pushing the parser/applier intosetOperation.ts(which only importsIConfigurationas a type,optionAliases, andVimError) breaks the cycle cleanly.test/cmd_line/set.test.tscovers parse-and-apply forclipboard=unnamed,clipboard=unnamedplus, clearing, and the interaction withuseSystemClipboard.test/configuration/vimrc.test.tsgains anapplySetLinesuite covering theset/seshort form, leading whitespace, non-set passthrough, and swallowed-unknown-option behavior.rm -rf out/ && yarn build-test && yarn test) — 3167 passing, 0 failing.yarn build,yarn lintalso clean.