Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ojroques/nvim-osc52
A Neovim plugin to copy text through SSH with OSC52
https://github.com/ojroques/nvim-osc52
nvim-plugin osc52
Last synced: 12 days ago
JSON representation
A Neovim plugin to copy text through SSH with OSC52
- Host: GitHub
- URL: https://github.com/ojroques/nvim-osc52
- Owner: ojroques
- License: bsd-2-clause
- Created: 2022-07-16T07:14:58.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-24T14:24:15.000Z (6 months ago)
- Last Synced: 2024-10-12T22:34:13.231Z (about 1 month ago)
- Topics: nvim-plugin, osc52
- Language: Lua
- Homepage:
- Size: 26.4 KB
- Stars: 344
- Watchers: 6
- Forks: 12
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nvim-osc52
**Note**: As of Neovim 10.0 (specifically since [this
PR](https://github.com/neovim/neovim/pull/25872)), native support for OSC52 has
been added and therefore this plugin is now obsolete. Check `:h clipboard-osc52`
for more details.A Neovim plugin to copy text to the system clipboard using the ANSI OSC52
sequence.The plugin wraps a piece of text inside an OSC52 sequence and writes it to
Neovim's stderr. When your terminal detects the OSC52 sequence, it will copy the
text into the system clipboard.This is totally location-independent, you can copy text from anywhere including
from remote SSH sessions. The only requirement is that your terminal must
support OSC52 which is the case for most modern terminal emulators.nvim-osc52 is a rewrite of
[vim-oscyank](https://github.com/ojroques/vim-oscyank) in Lua.## Installation
With [packer.nvim](https://github.com/wbthomason/packer.nvim) for instance:
```lua
use {'ojroques/nvim-osc52'}
```### Configuration for tmux
If you are using tmux, run these steps first: [enabling OSC52 in
tmux](https://github.com/tmux/tmux/wiki/Clipboard#quick-summary).Then, you can use the tmux option `set-clipboard on` or `allow-passthrough on`.
For tmux versions before 3.3a, you will need to use the `set-clipboard` option:
`set -s set-clipboard on`For tmux versions starting with 3.3a, you can configure tmux to allow passthrough
of escape sequences (`set -g allow-passthrough on`). With this option you can leave
`set-clipboard` to its default (`external`).
The allow-passthrough option works well for nested tmux sessions or when running
tmux on both the local and remote servers. When using allow-passthrough, be sure
to enable `tmux_passthrough` for this plugin.## Usage
Add this to your config (assuming Neovim 0.7+):
```lua
vim.keymap.set('n', 'c', require('osc52').copy_operator, {expr = true})
vim.keymap.set('n', 'cc', 'c_', {remap = true})
vim.keymap.set('v', 'c', require('osc52').copy_visual)
```Using these mappings:
* In normal mode, \c is an operator that will copy the given
text to the clipboard.
* In normal mode, \cc will copy the current line.
* In visual mode, \c will copy the current selection.## Configuration
The available options with their default values are:
```lua
require('osc52').setup {
max_length = 0, -- Maximum length of selection (0 for no limit)
silent = false, -- Disable message on successful copy
trim = false, -- Trim surrounding whitespaces before copy
tmux_passthrough = false, -- Use tmux passthrough (requires tmux: set -g allow-passthrough on)
}
```## Advanced usage
The following methods are also available:
* `require('osc52').copy(text)`: copy text `text`
* `require('osc52').copy_register(register)`: copy text from register `register`For instance, to automatically copy text that was yanked into register `+`:
```lua
function copy()
if vim.v.event.operator == 'y' and vim.v.event.regname == '+' then
require('osc52').copy_register('+')
end
endvim.api.nvim_create_autocmd('TextYankPost', {callback = copy})
```## Using nvim-osc52 as clipboard provider
You can use the plugin as your clipboard provider, see `:h provider-clipboard`
for more details. Simply add these lines to your config:
```lua
local function copy(lines, _)
require('osc52').copy(table.concat(lines, '\n'))
endlocal function paste()
return {vim.fn.split(vim.fn.getreg(''), '\n'), vim.fn.getregtype('')}
endvim.g.clipboard = {
name = 'osc52',
copy = {['+'] = copy, ['*'] = copy},
paste = {['+'] = paste, ['*'] = paste},
}-- Now the '+' register will copy to system clipboard using OSC52
vim.keymap.set('n', 'c', '"+y')
vim.keymap.set('n', 'cc', '"+yy')
```Note that if you set your clipboard provider like the example above, copying
text from outside Neovim and pasting with p won't work. But you can
still use the paste shortcut of your terminal emulator (usually
ctrl+shift+v).