Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to remain the system clipboard content when exit yazi.nvim? #658

Open
Laughing-q opened this issue Jan 7, 2025 · 12 comments
Open

How to remain the system clipboard content when exit yazi.nvim? #658

Laughing-q opened this issue Jan 7, 2025 · 12 comments

Comments

@Laughing-q
Copy link

Laughing-q commented Jan 7, 2025

@mikavilpas Hi thanks for the great work here! Recently I was switching my primary file manager from lf to yazi and currently looking into yazi.nvim as well from lf.nvim.
One of my usually workflows would be open the file manager inside neovim(currently it's yazi.nvim) and jump to another folder by the pre-defined shortcuts and copy the folder path or some filenames inside the folder(by using shortcuts of yazi, copy path and copy-dirname) then quit the file manager then paste the content in my code.
It worked with lf.nvim but when switching to yazi.nvim the content in system clipboard are gone when I exit the window of yazi.nvim.
Do you have any ideas that I could remain the copied content while quitting the yazi.nvim window? Thanks!

EDIT: I also tested with following this reproducing issues guide and the content are still gone to me. https://github.com/mikavilpas/yazi.nvim/blob/main/documentation/reproducing-issues.md

@mikavilpas
Copy link
Owner

I noticed I got the same behaviour in the reproduction environment.

no-register.mov

However, if I add this setting vim.opt.clipboard = "unnamedplus" it works.

clipboard.mov

@mikavilpas
Copy link
Owner

This is a really good point - thanks for reporting. I was not aware that my neovim distro (lazyvim) sets this on by default (here)

I'll add something that makes this more obvious, maybe a notice in the :checkhealth yazi if it's not on.

@mikavilpas
Copy link
Owner

@Laughing-q
Copy link
Author

Laughing-q commented Jan 7, 2025

@mikavilpas Thanks for the response! However actually I already have vim.opt.clipboard = "unnamedplus" here in my neovim configuration all the time since I need the shared clipboard between neovim and system: https://github.com/Laughing-q/nvim/blob/e4f79cca868122090249809c440870530a32d5c8/plugin/options.lua#L3 but does not seem to work to me on yazi.nvim.
Also for the reproduction env I tried manually adding vim.opt.clipboard = "unnamedplus" at the end of repro.lua but still not working to me.
https://github.com/user-attachments/assets/87a2868d-4b9f-40b0-b45c-e33b6405d0fd

EDIT: Is it possible I added it in an inappropriate position? where did you put the vim.opt.clipboard = "unnamedplus" in the repro.lua?

@mikavilpas
Copy link
Owner

I put it here 😄

Details

-- You can use this file to reproduce an issue with your configuration.

---@module "yazi"
---@module "lazy"

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)
vim.g.mapleader = " "
vim.opt.clipboard = "unnamedplus" -- 👈🏻

-- install the following plugins
---@type LazySpec
local plugins = {
  { "catppuccin/nvim", name = "catppuccin", opts = { flavour = "macchiato" } },
  {
    "mikavilpas/yazi.nvim",
    event = "VeryLazy",
    keys = {
      {
        "<leader>-",
        "<cmd>Yazi<cr>",
        desc = "Open yazi at the current file",
      },
      {
        -- Open in the current working directory
        "<leader>cw",
        "<cmd>Yazi cwd<cr>",
        desc = "Open the file manager in nvim's working directory",
      },
      {
        -- NOTE: this requires a version of yazi that includes
        -- https://github.com/sxyazi/yazi/pull/1305 from 2024-07-18
        "<c-up>",
        "<cmd>Yazi toggle<cr>",
        desc = "Resume the last yazi session",
      },
    },
    ---@type YaziConfig
    opts = {
      open_for_directories = false,
      log_level = vim.log.levels.DEBUG,
    },
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
  install = { colorscheme = { "catppuccin" } },
})

vim.cmd.colorscheme("catppuccin")
-- add anything else here

@mikavilpas
Copy link
Owner

Can you see if it works for you if you open :term, and then open yazi in there?

@Laughing-q
Copy link
Author

@mikavilpas yeah using :term and open yazi directly works to me.
The most strange part is that it seems like the "+" register is cleaned up once I close the yazi.nvim window, because if I let the window remains there and create another file using neovim and the content on clipboard remains there too. Once I closed the yazi.nvim window then the content gone.
https://github.com/user-attachments/assets/9e07b620-6c65-488d-ae4e-a47614744848

@mikavilpas
Copy link
Owner

The only place yazi.nvim should change the clipboard related registers is when you use the copy_relative_path_to_selected_files, which copies the path (here) to the selected file(s) from the place where yazi was started.

That should only be done when you enter the keybinding for that (the default is <c-y>).

What version of neovim do you have? I'm trying to think what could cause this.

@mikavilpas
Copy link
Owner

Is there something else on your system that might interfere with this?

  • neovim version
  • shell config (e.g. ~/.zshrc). You could try temporarily installing another shell, e.g. fish, and seeing if this still occurs
  • tmux/zellij
  • yazi config and yazi plugins

The reproduction environment does not account for all of these things, but I suppose they might play a role.

@mikavilpas
Copy link
Owner

Also, can you post the results of

  • :checkhealth provider.clipboard
  • :checkhealth yazi
  • yazi --debug

I should compare my values to yours. Here is what I have:

:checkhealth provider.clipboard

Details

==============================================================================
provider.clipboard: require("provider.clipboard.health").check()

Clipboard (optional) ~
- OK Clipboard tool found: pbcopy

:checkhealth yazi

Details

==============================================================================
yazi: require("yazi.health").check()

yazi ~
- Running yazi.nvim version 6.11.1
- Found `yazi` version `Yazi 0.4.3 (d754ac5d 2024-12-26)` 👍
- yazi.nvim log file is at /Users/mikavilpas/.local/state/nvim/yazi.log
-     hint: use `gf` to open the file path under the cursor
- Found `ya` version `Ya 0.4.3 (d754ac5d 2024-12-26)` 👍
- You have enabled `open_for_directories` in your config. Because of this, please make sure you are loading yazi when Neovim starts.

yazi.config ~
- hint: execute the following command to see your configuration: >
  :lua =require('yazi').config
  
- OK yazi

yazi --debug

Details

Yazi
    Version: 0.4.3 (d754ac5d 2024-12-26)
    Debug  : false
    Triple : aarch64-apple-darwin (macos-aarch64)
    Rustc  : 1.85.0-nightly (7c002ff9 2024-12-25)

Ya
    Version: 0.4.3 (d754ac5d 2024-12-26)

Emulator
    Brand.from_env      : Some(WezTerm)
    Emulator.detect     : Emulator { kind: Left(WezTerm), light: false, cell_size: Some((23, 45)) }
    Emulator.detect_full: Ok(Emulator { kind: Left(WezTerm), light: false, cell_size: Some((23, 45)) })

Adapter
    Adapter.matches: Iip

Desktop
    XDG_SESSION_TYPE           : None
    WAYLAND_DISPLAY            : None
    DISPLAY                    : Some("/private/tmp/com.apple.launchd.NB6PrLGgUg/org.xquartz:0")
    SWAYSOCK                   : None
    HYPRLAND_INSTANCE_SIGNATURE: None
    WAYFIRE_SOCKET             : None

SSH
    shared.in_ssh_connection: false

WSL
    WSL: false

NVIM
    NVIM          : false
    Neovim version: 0.10.3

Variables
    SHELL           : Some("/bin/zsh")
    EDITOR          : Some("nvim")
    VISUAL          : None
    YAZI_FILE_ONE   : None
    YAZI_CONFIG_HOME: None
    YAZI_ZOXIDE_OPTS: None
    FZF_DEFAULT_OPTS: Some(" --color=bg+:#363a4f,bg:#24273a,spinner:#f4dbd6,hl:#ed8796 --color=fg:#cad3f5,header:#ed8796,info:#c6a0f6,pointer:#f4dbd6 --color=marker:#b7bdf8,fg+:#cad3f5,prompt:#c6a0f6,hl+:#ed8796 --color=selected-bg:#494d64 --multi")

Text Opener
    default     : Some(Opener { run: "${EDITOR:=vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block-create: Some(Opener { run: "${EDITOR:=vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block-rename: Some(Opener { run: "${EDITOR:=vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })

Multiplexers
    TMUX               : 0
    tmux version       : tmux 3.5a
    tmux build flags   : enable-sixel=Unknown
    ZELLIJ_SESSION_NAME: None
    Zellij version     : 0.40.1

Dependencies
    file          : 5.41
    ueberzugpp    : 2.9.2
    ffmpeg/ffprobe: 7.1 / 7.1
    pdftoppm      : 24.04.0
    magick        : 7.1.1-39
    fzf           : 0.55.0
    fd/fdfind     : 10.2.0 / No such file or directory (os error 2)
    rg            : 14.1.1
    chafa         : 1.14.4
    zoxide        : 0.9.6
    7z/7zz        : No such file or directory (os error 2) / 24.09
    jq            : 1.7.1

Clipboard
    wl-copy/paste: No such file or directory (os error 2) / No such file or directory (os error 2)
    xclip        : No such file or directory (os error 2)
    xsel         : No such file or directory (os error 2)

@Laughing-q
Copy link
Author

Laughing-q commented Jan 7, 2025

@mikavilpas Yeah I think probably there's something else impacting this behavior but I don't know what's that yet. Thanks a lot for the info here! And here's my neovim version and the outputs:

neovim version
NVIM v0.10.3
Build type: RelWithDebInfo
LuaJIT 2.1.1731601260
Run "nvim -V1 -v" for more info

and yes I'm using zsh and tmux(I also tested outside tmux and remains the same issue).
And here's my yazi config.

:checkhealth provider.clipboard
provider.clipboard: require("provider.clipboard.health").check()

Clipboard (optional) ~
- OK Clipboard tool found: xsel
:checkhealth yazi
yazi: require("yazi.health").check()

yazi ~
- Running yazi.nvim version 6.11.1
- Found `yazi` version `Yazi 0.4.1 (Arch Linux 2024-12-19)` 👍
- yazi.nvim log file is at /home/laughing/.local/state/nvim/yazi.log
-     hint: use `gf` to open the file path under the cursor
- Found `ya` version `Ya 0.4.1 (Arch Linux 2024-12-19)` 👍

yazi.config ~
- hint: execute the following command to see your configuration: >
  :lua =require('yazi').config
  
- OK yazi
yazi --debug
Yazi
    Version: 0.4.1 (Arch Linux 2024-12-19)
    Debug  : false
    Triple : x86_64-unknown-linux-gnu (linux-x86_64)
    Rustc  : 1.83.0 (90b35a62 2024-11-26)

Ya
    Version: 0.4.1 (Arch Linux 2024-12-19)

Emulator
    Brand.from_env      : None
    Emulator.detect     : Emulator { kind: Right(Unknown { kgp: false, sixel: false }), light: false, cell_size: Some((12, 26)) }
    Emulator.detect_full: Ok(Emulator { kind: Right(Unknown { kgp: false, sixel: false }), light: false, cell_size: Some((12, 26)) })

Adapter
    Adapter.matches: X11

Desktop
    XDG_SESSION_TYPE           : Some("tty")
    WAYLAND_DISPLAY            : None
    DISPLAY                    : Some(":0")
    SWAYSOCK                   : None
    HYPRLAND_INSTANCE_SIGNATURE: None
    WAYFIRE_SOCKET             : None

SSH
    shared.in_ssh_connection: false

WSL
    WSL: false

NVIM
    NVIM          : false
    Neovim version: 0.10.3

Variables
    SHELL           : Some("/usr/bin/zsh")
    EDITOR          : Some("nvim")
    VISUAL          : None
    YAZI_FILE_ONE   : None
    YAZI_CONFIG_HOME: None
    YAZI_ZOXIDE_OPTS: None
    FZF_DEFAULT_OPTS: Some("--bind=ctrl-k:down,ctrl-i:up")

Text Opener
    default     : Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block-create: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block-rename: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })

Multiplexers
    TMUX               : 2
    tmux version       : tmux 3.5a
    tmux build flags   : enable-sixel=Unknown
    ZELLIJ_SESSION_NAME: None
    Zellij version     : No such file or directory (os error 2)

Dependencies
    file          : 5.46
    ueberzugpp    : 2.9.6
    ffmpeg/ffprobe: 7.1 / 7.1
    pdftoppm      : 24.11.0
    magick        : 7.1.1-41
    fzf           : 0.57.0
    fd/fdfind     : 10.2.0 / No such file or directory (os error 2)
    rg            : 14.1.1
    chafa         : 1.14.5
    zoxide        : 0.9.6
    7z/7zz        : 24.09 / No such file or directory (os error 2)
    jq            : 1.6

Clipboard
    wl-copy/paste: No such file or directory (os error 2) / No such file or directory (os error 2)
    xclip        : 0.13
    xsel         : 1.2.1

@Laughing-q
Copy link
Author

@mikavilpas I saw we have different clipboard provider, do you think that might be the factor?

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

No branches or pull requests

2 participants