Home Explore Blog CI



neovim

4th chunk of `runtime/doc/provider.txt`
59c7494963f733c31fabddc7556d9cab2f31a695221f69db0000000100000987
 extend(g:, {'foo': [lines, regtype]}) },
      \    },
      \   'paste': {
      \      '+': {-> get(g:, 'foo', [])},
      \      '*': {-> get(g:, 'foo', [])},
      \   },
      \ }
<
							      *clipboard-wsl*
For Windows WSL, try this g:clipboard definition:
>vim
    let g:clipboard = {
      \   'name': 'WslClipboard',
      \   'copy': {
      \      '+': 'clip.exe',
      \      '*': 'clip.exe',
      \    },
      \   'paste': {
      \      '+': 'powershell.exe -NoLogo -NoProfile -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
      \      '*': 'powershell.exe -NoLogo -NoProfile -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
      \   },
      \   'cache_enabled': 0,
      \ }
<
							    *clipboard-osc52*
Nvim bundles a clipboard provider that allows copying to the system clipboard
using OSC 52, an "Operating System Command" control-sequence that causes the
terminal emulator to write to or read from the system clipboard.

When Nvim is running in the |TUI|, it automatically detects host terminal
support for OSC 52. If successful, then Nvim will use OSC 52 for copying and
pasting if no other |clipboard-tool| is found and when 'clipboard' is unset.
NOTE: Using a terminal multiplexer (e.g. tmux) may inhibit automatic OSC 52
support detection.

							*g:termfeatures*
To disable the automatic detection, set the "osc52" key of |g:termfeatures| to
false early in your |config|. Example: >lua
	local termfeatures = vim.g.termfeatures or {}
	termfeatures.osc52 = false
	vim.g.termfeatures = termfeatures
<
To force Nvim to use the OSC 52 provider you can set |g:clipboard|: >lua

    vim.g.clipboard = 'osc52'

Which is equivalent to: >lua
    vim.g.clipboard = {
      name = 'OSC 52',
      copy = {
        ['+'] = require('vim.ui.clipboard.osc52').copy('+'),
        ['*'] = require('vim.ui.clipboard.osc52').copy('*'),
      },
      paste = {
        ['+'] = require('vim.ui.clipboard.osc52').paste('+'),
        ['*'] = require('vim.ui.clipboard.osc52').paste('*'),
      },
    }
<
Note: not all terminal emulators support reading from the system clipboard
(and even for those that do, users should be aware of the security
implications), so using OSC 52 for pasting may not be possible (and not
necessary, because you can |paste| instead using your system paste function).
Users may need to configure their terminal emulator to allow reading

Title: WSL Clipboard, OSC 52 Clipboard, and Terminal Features
Summary
This section provides configuration details for specific clipboard scenarios, including a recommended setup for Windows Subsystem for Linux (WSL). It then explains the OSC 52 clipboard provider bundled with Nvim, which uses terminal control sequences to interact with the system clipboard. It details how Nvim automatically detects terminal support for OSC 52 and how to disable or force its use via the `g:termfeatures` and `g:clipboard` variables. It also notes the security implications and potential limitations of using OSC 52 for pasting, due to terminal emulator support.