Skip to content

Support :set clipboard=unnamed from vimrc#9985

Open
digitalby wants to merge 2 commits intoVSCodeVim:masterfrom
digitalby:feat/vimrc-set-clipboard
Open

Support :set clipboard=unnamed from vimrc#9985
digitalby wants to merge 2 commits intoVSCodeVim:masterfrom
digitalby:feat/vimrc-set-clipboard

Conversation

@digitalby
Copy link
Copy Markdown

What this PR does / why we need it:

Adds support for Vim's clipboard option, so that

set clipboard=unnamed
" or
set clipboard=unnamedplus

in 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 setting vim.useSystemClipboard, and any set clipboard=... line in a vimrc was silently dropped because the vimrc loader only processed key mappings, not :set lines.

The change is built in two logical commits:

1. refactor: extract :set parser and applier so non-interactive callers can reuse them

  • Splits the parser, SetOperation type, option-alias lookup, and mutation logic out of src/cmd_line/commands/set.ts into a new src/cmd_line/commands/setOperation.ts that takes an IConfiguration by parameter instead of reaching for the singleton. SetCommand becomes a thin wrapper that still owns the interactive show / status-bar path.
  • Moves optionAliases into its own file (src/configuration/optionAliases.ts), re-exported from configuration.ts for backward compatibility.
  • Pure refactor; no behavior change. This was necessary to let the vimrc loader (which is itself dynamically imported from configuration.ts) reuse the same parser + mutation path without reintroducing a circular dependency.

2. feat: support vim clipboard option …

  • Adds vim.clipboard to package.json with enum ["", "unnamed", "unnamedplus"], default "".
  • Adds a matching clipboard field to IConfiguration / Configuration, plus a small clipboardAliasesUnnamedRegister getter that returns true when either useSystemClipboard is on or clipboard is set to unnamed / unnamedplus.
  • Replaces the three existing configuration.useSystemClipboard read 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.
  • Teaches VimrcImpl.loadConfig (src/configuration/vimrc.ts) to recognize set … / se … lines and run them through setOperationParser + applyOperationToConfig. Parse failures and unknown options are logged via Logger.warn per 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 unnamed and unnamedplus map to the same behavior because VS Code exposes a single clipboard concept — there's no separate PRIMARY selection 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:

  • The refactor commit is non-trivial but mechanical: the old switch is moved verbatim into applyOperationToConfig(config, op) with all configuration[option] = … assignments rewritten to config[option] = …. The interactive show / show_or_set-on-string branches still live in SetCommand.execute because they need a VimState for the status bar.
  • The circular-dependency plugin is the reason for the split: configuration.ts dynamically imports vimrc.ts, so vimrc.ts can't statically import anything that reaches configuration.ts. Pushing the parser/applier into setOperation.ts (which only imports IConfiguration as a type, optionAliases, and VimError) breaks the cycle cleanly.
  • Tests: new test/cmd_line/set.test.ts covers parse-and-apply for clipboard=unnamed, clipboard=unnamedplus, clearing, and the interaction with useSystemClipboard. test/configuration/vimrc.test.ts gains an applySetLine suite covering the set / se short form, leading whitespace, non-set passthrough, and swallowed-unknown-option behavior.
  • Full suite after a clean rebuild (rm -rf out/ && yarn build-test && yarn test) — 3167 passing, 0 failing. yarn build, yarn lint also clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant