Code Monkey home page Code Monkey logo

nvim-osc52's People

Contributors

kmac avatar lvxnull avatar ojroques avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nvim-osc52's Issues

failed to copy text with mouse after using nvim-osc52 inside the tmux in kitty

Reproduction steps:

  1. launch kitty, run tmux locally.
  2. inside tmux, select text A using mouse, and paste with ctrl-shift-v, which output text A as expect
  3. inside tmux, launch a pane, open nvim with nvim-osc52 installed and edit a file
  4. copy text B in neovim with yy
  5. paste in another pane in tmux, which works well
  6. select text A using mouse again, and paste with ctrl-shift-v, which output text B
  7. change kitty to other terminals like alacritty, repeat steps 1-6, the problem disappears.
  8. launch kitty, ssh to remote server and run tmux, repeat steps 1-6, the problem also disappears.

Minimal Configuration:

tmux

set -ga terminal-overrides ",xterm*:Tc"
set-option -g status-interval 5
set-option -g automatic-rename on
set-option -g automatic-rename-format '#{b:pane_current_path}'
set-environment -g COLORTERM "truecolor"
set -s set-clipboard on
set -g mouse on

kitty: default configuration

nvim-osc52 configuration:

require('osc52').setup {
    max_length       = 0,    -- Maximum length of selection (0 for no limit)
    silent           = true, -- Disable message on successful copy
    trim             = true, -- Trim surrounding whitespaces before copy
    tmux_passthrough = true, -- Copy from tmux into vim
}

I'm very confused about this issue, since if I running the following osc52 command in tmux and kitty, the problem won't happened:

esc="\033]52;c;$(base64 <<< 'hello world')\a"
esc="\033Ptmux;\033$esc\033\\" # tmux needs sequence escapement
printf "$esc"

Finally, thanks for your plugin which improves my remote development experience.

osc52.copy_visual is copying one more character than selected

I just tried nvim + osc52 plugin in patched konsole with OSC52 support (Linux, KDE Plasma) and there a problem with visual selection function.

Basically, when selecting some piece of text, the plugin copies that plus an additional character after that. And if that selection runs intil the end of the line for example, that will include \n.

It even reports N+1 characters copied when I selected only N (just checked).

Here is my configuration for it:

" OSC-52 clipboard handling
lua <<EOF
osc52 = require('osc52')

osc52 .setup { 
  silent = false
}

vim.keymap.set('x', '<C-c>', osc52.copy_visual)
EOF

The way I'm using it - in visual mode select something, then press Ctrl+C. It copes things, but as above, there is that length problem.

Bug: first invocation doesn't copy

When first launching neovim, the first use of the y operator doesn't copy. I get the message that 'osc52' copied x characters but when trying to put that test using p I get: E353: Nothing in register ". Subsequent uses work as expected.

This is consistent in multiple setups I use.

Default leader copy command cuts buffer text

Hi @ojroques,

Thanks for making this and the upstream vim-oscyank. Not able to find the right solution to override the which-key config based on the upstream Lunar Vim docs and source code.

When hitting <Space>c in normal mode, it complains about E16: Invalid range. Switching to visual mode, it copies to the system clipboard, but then cuts the text from the open buffer.

Any idea why it's behaving like this?

Thanks in advance! ๐Ÿ™

Kapture.2022-11-26.at.17.49.21.mp4

OS: macOS 12.6.1 (21G217)
iTerm: 3.4.16
neovim: v0.8.1
lvim: 1.2.0 (4d03f65)
config.lua

--[[
lvim is the global options object

Linters should be
filled in as strings with either
a global executable or a path to
an executable
]]

-- general
lvim.log.level = "warn"
lvim.format_on_save = true
-- lvim.colorscheme = "onedarker"
lvim.colorscheme = "onenord"
-- to disable icons and use a minimalist setup, uncomment the following
lvim.use_icons = true

-- keymappings [view all the defaults by pressing <leader>Lk]
lvim.leader = "space"
-- add your own keymapping
lvim.keys.normal_mode["<C-s>"] = ":w<cr>"
-- unmap a default keymapping
-- vim.keymap.del("n", "<C-Up>")
-- override a default keymapping
-- lvim.keys.normal_mode["<C-q>"] = ":q<cr>" -- or vim.keymap.set("n", "<C-q>", ":q<cr>" )

-- TODO: fix osc52 "<leader>c/cc" cutting lines
-- disable close buffer default keybinding
lvim.keys.normal_mode["<leader>c"] = false
lvim.keys.visual_mode["<leader>c"] = false

-- osc52 copy function
function copy()
  if vim.v.event.operator == 'y' and vim.v.event.regname == 'c' then
    require('osc52').copy_register('c')
  end
end

vim.api.nvim_create_autocmd('TextYankPost', {callback = copy})

-- nvim-osc52 clipboard provider
local function copy(lines, _)
  require('osc52').copy(table.concat(lines, '\n'))
end

local function paste()
  return {vim.fn.split(vim.fn.getreg(''), '\n'), vim.fn.getregtype('')}
end

vim.g.clipboard = {
  name = 'osc52',
  copy = {['+'] = copy, ['*'] = copy},
  paste = {['+'] = paste, ['*'] = paste},
}

-- Now the '+' register will copy to system clipboard using OSC52
vim.keymap.set('n', '<leader>c', '"+y')
vim.keymap.set('n', '<leader>cc', '"+yy')

-- osc52 keymap
vim.keymap.set("n", "<leader>c", require("osc52").copy_operator, {expr = true})
vim.keymap.set("n", "<leader>cc", "<leader>c_", {remap = true})
vim.keymap.set("x", "<leader>c", require("osc52").copy_visual)

-- custom whichkey mapping
lvim.builtin.which_key.mappings = {
  -- ["c"] = { "<cmd>BufferKill<CR>", "Close Buffer" },   -- default
  ["c"] = { "<cmd>copy<CR>", "Copy Selection" },          -- osc52
  [";"] = { "<cmd>Alpha<CR>", "Dashboard" },
  ["w"] = { "<cmd>w!<CR>", "Save" },
  ["q"] = { "<cmd>lua require('lvim.utils.functions').smart_quit()<CR>", "Quit" },
  ["/"] = { "<Plug>(comment_toggle_linewise_current)", "Comment toggle current line" },
  ["f"] = { require("lvim.core.telescope.custom-finders").find_project_files, "Find File" },
  ["h"] = { "<cmd>nohlsearch<CR>", "No Highlight" },
  ["e"] = { "<cmd>NvimTreeToggle<CR>", "Explorer" },
  b = {
    name = "Buffers",
    j = { "<cmd>BufferLinePick<cr>", "Jump" },
    f = { "<cmd>Telescope buffers<cr>", "Find" },
    b = { "<cmd>BufferLineCyclePrev<cr>", "Previous" },
    n = { "<cmd>BufferLineCycleNext<cr>", "Next" },
    e = {
      "<cmd>BufferLinePickClose<cr>",
      "Pick which buffer to close",
    },
    h = { "<cmd>BufferLineCloseLeft<cr>", "Close all to the left" },
    l = {
      "<cmd>BufferLineCloseRight<cr>",
      "Close all to the right",
    },
    D = {
      "<cmd>BufferLineSortByDirectory<cr>",
      "Sort by directory",
    },
    L = {
      "<cmd>BufferLineSortByExtension<cr>",
      "Sort by language",
    },
  },
  d = {
    name = "Debug",
    t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" },
    b = { "<cmd>lua require'dap'.step_back()<cr>", "Step Back" },
    c = { "<cmd>lua require'dap'.continue()<cr>", "Continue" },
    C = { "<cmd>lua require'dap'.run_to_cursor()<cr>", "Run To Cursor" },
    d = { "<cmd>lua require'dap'.disconnect()<cr>", "Disconnect" },
    g = { "<cmd>lua require'dap'.session()<cr>", "Get Session" },
    i = { "<cmd>lua require'dap'.step_into()<cr>", "Step Into" },
    o = { "<cmd>lua require'dap'.step_over()<cr>", "Step Over" },
    u = { "<cmd>lua require'dap'.step_out()<cr>", "Step Out" },
    p = { "<cmd>lua require'dap'.pause()<cr>", "Pause" },
    r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Toggle Repl" },
    s = { "<cmd>lua require'dap'.continue()<cr>", "Start" },
    q = { "<cmd>lua require'dap'.close()<cr>", "Quit" },
    U = { "<cmd>lua require'dapui'.toggle()<cr>", "Toggle UI" },
  },
}

-- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile
lvim.builtin.alpha.active = true
lvim.builtin.alpha.mode = "dashboard"
lvim.builtin.terminal.active = true
lvim.builtin.nvimtree.setup.view.side = "left"
lvim.builtin.nvimtree.setup.renderer.icons.show.git = false

-- if you don't want all the parsers change this to a table of the ones you want
lvim.builtin.treesitter.ensure_installed = {
  "bash",
  "c",
  "javascript",
  "json",
  "lua",
  "python",
  "typescript",
  "tsx",
  "css",
  "rust",
  "java",
  "yaml",
}

lvim.builtin.treesitter.ignore_install = { "haskell" }
lvim.builtin.treesitter.highlight.enabled = true

-- -- set additional linters
-- local linters = require "lvim.lsp.null-ls.linters"
-- linters.setup {
--   { command = "flake8", filetypes = { "python" } },
--   {
--     -- each linter accepts a list of options identical to https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md#Configuration
--     command = "shellcheck",
--     ---@usage arguments to pass to the formatter
--     -- these cannot contain whitespaces, options such as `--line-width 80` become either `{'--line-width', '80'}` or `{'--line-width=80'}`
--     extra_args = { "--severity", "warning" },
--   },
--   {
--     command = "codespell",
--     ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
--     filetypes = { "javascript", "python" },
--   },
-- }

-- Additional Plugins
lvim.plugins = {
  -- {"folke/tokyonight.nvim"},
  { "arcticicestudio/nord-vim" },
  {
    "folke/todo-comments.nvim",
    event = "BufRead",
    config = function()
      require("todo-comments").setup()
    end,
  },
  { "kassio/neoterm" },
  { "ojroques/nvim-osc52" },
  { "rmehri01/onenord.nvim" },
  { "wfxr/minimap.vim" }
}

-- Autocommands (https://neovim.io/doc/user/autocmd.html)
-- vim.api.nvim_create_autocmd("BufEnter", {
--   pattern = { "*.json", "*.jsonc" },
--   -- enable wrap mode for json files only
--   command = "setlocal wrap",
-- })
-- vim.api.nvim_create_autocmd("FileType", {
--   pattern = "zsh",
--   callback = function()
--     -- let treesitter use bash highlight for zsh files as well
--     require("nvim-treesitter.highlight").attach(0, "bash")
--   end,
-- })

trim with multiple lines

When copying multiple lines with the trim option enabled, only the first whitespace is trimmed.
E.g. when copying:

# some class code here
     def foo(self, bar):
         return bar * 2

You will get:

def foo(self, bar):
        return bar * 2

This is of course because the copy function takes the full string, so it cannot know the lines (except if it would split them again, which will end up in concatting, splitting and concatting again in many cases).

I've created a small function that strips the common indent of the copied lines:

local copy = function(lines, _)
  -- Trim indent before copying
  local indent, _ = lines[1]:find '[^ ]'
  for key, line in ipairs(lines) do
    lines[key] = line:sub(indent)
  end
  require('osc52').copy(table.concat(lines, '\n'))
end

I wonder if this would be something worth integrating? Or mentioning in the README?

I still need to handle cases where the first line(s) are empty, probably could be done in a better way.

Unexpected behavior when first invocation is in visual mode

When nvim-osc52 has not been previously invoked since Neovim was launched, an attempt to invoke it via copy_visual (per the recommended keybindings, <leader>c) does not properly copy the visual selection. Instead, the plugin appears to target results for the most recently used search pattern.

Expected behavior:
The visually selected text should be copied to the system clipboard.

Actual behavior (two variants):

  1. The search pattern is found
    • The visual selection is adjusted by the cursor jumping to the pattern's location in the buffer
    • The copied text is the search pattern instead of the visually selected text
  2. The search pattern is not found
    • Neovim throws the following error:
    E5108: Error executing lua: ...are/nvim/site/pack/packer/start/nvim-osc52/lua/osc52.lua:31: Vim(normal):E486: Pattern not found: hello
    stack traceback:
            [C]: in function 'cmd'
            ...are/nvim/site/pack/packer/start/nvim-osc52/lua/osc52.lua:31: in function 'get_text'
            ...are/nvim/site/pack/packer/start/nvim-osc52/lua/osc52.lua:93: in function <...are/nvim/site/pack/packer/start/nvim-osc52/lua/osc52.lua:92>
    

Any subsequent invocations of nvim-osc52 within the same session appear to be handled properly.

Copying does not overwrite

I got a weird issue.
When using plugin on macos everything works fine, copying overwrites old copy.
But with the same terminal(kitty) with the same nvim config but on linux, copying does not overwrite itself. New lines are added to last copy and so on.
Any ideas how to fix this?

Example configuration behaves unexpectedly (LazyVim)

Using LazyVim via this configuration:

return {
  "ojroques/nvim-osc52",
  keys = {
    {
      "<leader>y",
      function() require("osc52").copy_operator() end,
      expr = true,
      desc = "copy selection to system clipboard (normal mode)"
    },
    {
      "<leader>Y",
      "<leader>c_",
      remap = true,
      desc = "copy current line into system clipboard (normal mode)"
    },
    {
      mode = "v",
      "<leader>y",
      function() require("osc52").copy_visual() end,
      desc = "copy selection to system clipboard (visual mode)"
    }
  }
}
  • Using <leader>y in normal mode appears to do nothing. โŒ
  • Using <leader>Y deletes the current line, and puts me into insert mode. โŒ
  • Using <leader>y in visual mode works as expected, text is yanked to my system clipboard via osc52 and a message is printed confirming that. โœ…

Maybe I don't understand the purpose of <leader>y โ†’ require("osc52").copy_operator() mapping in normal mode, but as mentioned I see no effect. <leader>Y โ†’ <leader>c_ in normal mode is most definitely not copying the currently highlighted line; as I assume that mapping would, given the example configuration's descriptions:

vim.keymap.set('n', '<leader>c', require('osc52').copy_operator, {expr = true})
vim.keymap.set('n', '<leader>cc', '<leader>c_', {remap = true})
vim.keymap.set('v', '<leader>c', require('osc52').copy_visual)

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.

The second map (normal mode <leader>y) is doing something, just the wrong thing. Changing the second value, or what the map is being remapped to changes the behavior. I say this because that means that my syntax / configuration is correct in the sense that something is happening, just not the right something. And as previously mentioned, the visual mode mapping works as expected. Using native remapping has an identical effect to the LazyVim syntax remapping.

vim.keymap.set("n", "<leader>Y", "<leader>c_", { remap = true, desc = "copy current line to system clipboard (normal mode)" })

I'm skeptical of replacing my clipboard provider entirely with osc52 as I run the potential risk of using a terminal that doesn't provide osc52 support, and losing access to basic clipboard functionality. So, I'd love to get this working without resorting to that.

Cannot copy more than 700 characters.

When I select around 800 characters, it just hang, clipboard is emptied and no-response window. I have to move a to different windows and back to get the window to be responsive again.

  use {'ojroques/nvim-osc52',
    config = function ()
      local function copy(lines, _)
        require('osc52').copy(table.concat(lines, '\n'))
      end
      local function paste()
        return {vim.fn.split(vim.fn.getreg(''), '\n'), vim.fn.getregtype('')}
      end
      vim.g.clipboard = {
        name = 'osc52',
        copy = {['+'] = copy, ['*'] = copy},
        paste = {['+'] = paste, ['*'] = paste},
      }
      -- Now the '+' register will copy to system clipboard using OSC52
    end
  }

No problem whatsoever with the old vimscript plugin though.

  use {"ojroques/vim-oscyank", 
  config = function()
    vim.cmd [[ autocmd TextYankPost * if v:event.operator is 'y' && v:event.regname is '+' | execute 'OSCYankReg +' | endif ]]
  end }

Yank line and paste not working with osc52

Thank you for making a great plugin! It's so great to be able to copy text even over an ssh session!

However, after setting up the plugin, I have noticed that my usual workflow of copying and pasting lines (yy and p) no longer works. I get the error:

E353: Nothing in register "

I have set the following in my config:

vim.opt.clipboard = "unnamedplus"

local status_ok, osc52 = pcall(require, "osc52")
if not status_ok then
    return
end

osc52.setup({
    max_length = 0, -- Maximum length of selection (0 for no limit)
    silent = false, -- Disable message on successful copy
    trim = false, -- Trim text before copy
})

-- set this plugin as the clipboard provider
local function copy(lines, _)
    require('osc52').copy(table.concat(lines, '\n'))
end

local function paste()
    return {vim.fn.split(vim.fn.getreg(''), '\n'), vim.fn.getregtype('')}
end

vim.g.clipboard = {
    name = 'osc52',
    copy = {['+'] = copy, ['*'] = copy },
    paste = {['+'] = paste, ['*'] = paste },
}

Is there anything I can do to re-enable my copy-line-and-paste workflow? I am new to Neovim so apologies if I am missing something obvious.

osc52.copy always writes to /dev/fd/2 because vim.fn.filewritable always succeeds, even when the file does not exist

Hello!

Thanks for writing this plugin! Unfortunately, I am connecting to a Windows machine via SSH and the osc52.copy function will fail every time because vim.fn.filewritable does not return a boolean but instead returns 0. In lua, only nil and false are actually false

That said, I can say the else block does work correctly if a small patch is applied:

  if vim.fn.filewritable('/dev/fd/2') ~= 0 then

I've applied this and some more experimental stuff (like using the builtin function vim.notify for errors/status messages) so I couldn't just open a PR directly to fix this, as I've hacked this plugin up quiet a bit on my end ๐Ÿ˜…

auto copy contents from register not working as expected

I used the config provided in the readme

function copy()
  if vim.v.event.operator == 'y' and vim.v.event.regname == '+' then
    require('osc52').copy_register('+')
  end
end

vim.api.nvim_create_autocmd('TextYankPost', {callback = copy})

In this case, if I use "+yy to yank, the contents will be yanked to the system clipboard and I can paste it anywhere, but if I directly use yy to yank, nothing will be copied to the system clipboard, I used the :reg to checked the register, the contents is in the + register, why it is not copied to system clipboard?

difference between using as a clipboard provider vs not?

hi! relatively new to neovim here and trying to understand the difference between the two usages described in the readme

I see one usage looks like this:

vim.keymap.set('n', '<leader>c', require('osc52').copy_operator, {expr = true})
vim.keymap.set('n', '<leader>cc', '<leader>c_', {remap = true})

and the other looks via "clipboard provider" looks like:

local function copy(lines, _)
  require('osc52').copy(table.concat(lines, '\n'))
end

local function paste()
  return {vim.fn.split(vim.fn.getreg(''), '\n'), vim.fn.getregtype('')}
end

vim.g.clipboard = {
  name = 'osc52',
  copy = {['+'] = copy, ['*'] = copy},
  paste = {['+'] = paste, ['*'] = paste},
}

-- Now the '+' register will copy to system clipboard using OSC52
vim.keymap.set('n', '<leader>c', '"+y')
vim.keymap.set('n', '<leader>cc', '"+yy')

Questions:

  1. are these two approaches doing effectively the same thing?
    1a. if yes, maybe we can simplify readme to just have one approach?
    1b. if no, when would I use the clipboard provider approach as opposed to the keymap + provided functions approach?
  2. can we expose the copy and paste functions within the library itself so users don't need to specify them when using clipboard provider approach? sort of like what will come in neovim 0.10 require('vim.clipboard.osc52').copy?

Can't make it work with Mosh

Hi,

Thank you for the plugin! It sounds exactly what I was looking for ๐Ÿ”ฅ

My local OS is MacOS 14. I'm using iTerm2 to connect to a remote server with mosh. The remote server is running Ubuntu 22.04 and has mosh installed. I can connect to the server, and works perfectly, but the copy to local clipboard and paste from local clipboard functionality doesn't work. Is mosh supported?

If using ssh instead of mosh, things work, even without this plugin. I wanted to use this plugin hoping it would make the copy/paste from/to local clipboard work.

Feature: Query and paste from the clipboard

While most terminal emulates don't support reading from the clipboard, there is growing support for this feature โ€“ the next release of iTerm (3.5) will allow for querying the clipboard.

It'd be nice to support pasting for those who use a terminal emulator that supports querying the clipboard via OSC 52!

copy_visual does not respect reselect-visual (gv)

When pressing gv (:help reselect-visual), it should reselect the copied region (visual block).

Reproduction:

      vim.keymap.set('v', '<leader>y', require('osc52').copy_visual)
  • visual select some text
  • <leader>y (osc52.copy_visual)
  • move cursor
  • gv
  • The same visual region should be selected again, but it doesn't.

Some codes like the following would be needed:

local start = vim.fn.getpos("'<")
local end = vim.fn.getpos("'>")

-- copy OSC52...

vim.fn.setpos("'<", start)
vim.fn.setpos("'>", end)

Copying gets broken on long text

I was testing nvim-osc52 with nvim (0.7.2) and patched konsole with with osc52 support, and noticed that copying gets truncated on certain input (konsole patch here).

For example, copying osc52.lua itself from the source code, produces only this when pasting:

-------------------- VARIABLES -----------------------------
local base64 = require('base64')
local fmt = string.format
local commands = {
  operator = {block = "`[\\<C-v>`]y", char = "`[

I'm not sure if it's an issue with plugin or with konsole's handling of osc52.

Can I paste from local system clipboard to remote neovim by "p"?

This plugin is amazing!

Mac is my remote computer at Home, I use windows PC in office to access Mac over SSH
How can I psate from Windows PC clipboard to Mac neovim with key "p" over SSH๏ผŸ
Thank you

My Mac OS config with lazy.nvim:

return {
  {
    "ojroques/nvim-osc52",
    config = function()
      --vim.keymap.set("n", "<leader>c", require("osc52").copy_operator, { expr = true })
      --vim.keymap.set("n", "yy", "<leader>c_", { remap = true })
      --vim.keymap.set("v", "y", require("osc52").copy_visual)
      require("osc52").setup({
        silent = true,
      })
      function copy()
        if vim.v.event.operator == "y" and vim.v.event.regname == "+" then
          require("osc52").copy_register("+")
        end
      end
      vim.api.nvim_create_autocmd("TextYankPost", { callback = copy })
      local function copy(lines, _)
        require("osc52").copy(table.concat(lines, "\n"))
      end

      local function paste()
        return { vim.fn.split(vim.fn.getreg(""), "\n"), vim.fn.getregtype("") }
      end

      vim.g.clipboard = {
        name = "osc52",
        copy = { ["+"] = copy, ["*"] = copy },
        paste = { ["+"] = paste, ["*"] = paste },
      }
      -- Now the '+' register will copy to system clipboard using OSC52
      vim.keymap.set("n", "<leader>c", '"+y')
      vim.keymap.set("n", "<leader>cc", '"+yy')
    end,
  },
}

osc52 does not copy to tmux clipboard

Hello! I am having an odd issue in that I cannot seem to get osc52 to copy to tmux's system clipboard. I have verified that the tmux clipboard does work as I can copy things from neovim with tmux itself, but that is obviously painful.

I am using the default config in the readme

require('osc52').setup {
  max_length = 0,  -- Maximum length of selection (0 for no limit)
  silent = false,  -- Disable message on successful copy
  trim = false,    -- Trim text before copy
}

local function copy(lines, _)
  require('osc52').copy(table.concat(lines, '\n'))
end

local function paste()
  return {vim.fn.split(vim.fn.getreg(''), '\n'), vim.fn.getregtype('')}
end

vim.g.clipboard = {
  name = 'osc52',
  copy = {['+'] = copy, ['*'] = copy},
  paste = {['+'] = paste, ['*'] = paste},
}

-- Now the '+' register will copy to system clipboard using OSC52
vim.keymap.set('n', '<leader>c', '"+y')
vim.keymap.set('n', '<leader>cc', '"+yy')

Specifically, my config can be found here

Easy way to link to an arbitrary register

With the old version, I had this autocmd:

    autocmd TextYankPost * if v:event.operator is 'y' && v:event.regname is 'c' | execute 'OSCYankReg c' | endif

Which just made the "c" register my system clipboard. I use that along with remapped Control-c and Control-v so that those standard shortcuts copy to the local system when I want that but my "unnamed" register is used normally.

" Use Ctl+c/x/v as secondary clipboard
nnoremap <silent> <C-c> "cy
vnoremap <silent> <C-c> "cy
inoremap <silent> <C-c> <C-o>"cyiw

inoremap <silent> <C-x> <C-o>"cdiw
vnoremap <silent> <C-x> "cd
nnoremap <silent> <C-x> "cdiw

nnoremap <silent> <C-v> "cp
vnoremap <silent> <C-v> "cp
inoremap <silent> <C-v> <C-o>"cp
tnoremap <silent> <C-v> <c-\><c-n>"cpa

Can you tell me the equivalent setting in the new version?

Doesn't work inside tmux

This plugin works well outside tmux, but not inside a tmux session. I've set up tmux-osc52 well (https://github.com/tmux/tmux/wiki/Clipboard#quick-summary) and I can confirm it works:

# (inside a tmux)
esc="\033]52;c;$(base64 <<< 'hello world')\a"
esc="\033Ptmux;\033$esc\033\\" # tmux needs sequence escapement
printf "$esc"

The OSC52 sequence need to be wrapped and escaped properly to enable passthrough. However, the plugin doesn't seem to be aware of tmux escape sequences:

https://github.com/ojroques/nvim-osc52/blob/main/lua/osc52.lua#L58

disable printing status, return status, <leader>cc not working.

This can be very annoying for a global or absent statusline, because it must be confirmed via enter. Can you let the user configure this?

Would be also nice to know how to get the return status of your functions from lua code. I'd like to use my statusline instead of popups.

For me at least vim.keymap.set('n', '<leader>cc', '<leader>c_', {remap = true}) does not work properly. What is the underlying lua function to be used for this? To me '<leader>c_' looks like there is something sneaky hiding below waiting to clash with other keybindings.

Yank behavior on a remote machine: `yy` does not yank, but `"*yy` yanks

Here is a strange problem I could use help with from the good folks here. I'm using nvim-osc52 with nvim 0.7.2.

  • Config:

    • osc52 plugin enabled, g:clipboard set as shown at the bottom here (I don't use the leader mappings, but use everything else)
    • :set clipboard= is empty (not set)
    • Using WSL via Windows Terminal, Windows 10
    • "Clipboard" always means my local computer's clipboard (that I can paste using Ctrl+V into Notepad)
  • Behavior on a local machine <-- This is exactly the desired behavior

    • Works exactly as I want
    • yy and "*yy both yank to clipboard
    • cW does not yank to clipboard
  • Behavior on a remote machine (via ssh or mosh):

    • yy does not yank to clipboard <-- This is the problem
    • "*yy yanks to clipboard
    • cW does not yank to clipboard

Note that if I :set clipboard=unnamed, the behavior changes: yy works on the remote, but cW also copies to the clipboard (on both local and remote), which is not what I want.

Any idea at all what this could be or even how I could debug it? Thanks much in advance!

osc52.lua line 43: attempt to index global 'visual_marks' (a nil value)

  -- Save previous visual marks in operator mode
  if mode == 'operator' then
    local visual_marks = {vim.fn.getpos("'<"), vim.fn.getpos("'>")}
  end

  -- Retrieve text
  vim.go.clipboard = ''
  local command = fmt('keepjumps normal! %s', commands[mode][type])
  vim.cmd(fmt('silent execute "%s"', command))
  local text = vim.fn.getreg('"')

  -- Restore user settings
  vim.go.clipboard = clipboard
  vim.fn.setreg('"', register)

  -- Restore previous visual marks in operator mode
  if mode == 'operator' then
    vim.fn.setpos("'<", visual_marks[1])
    vim.fn.setpos("'>", visual_marks[2])
  end

  return text or ''
end

it seems like the visual_marks need to define out of the if statement?
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.