3rd / image.nvim

🖼️ Bringing images to Neovim.
MIT License
1.03k stars 42 forks source link

Image is still shown when switched to another tmux window #106

Open sahinakkaya opened 9 months ago

sahinakkaya commented 9 months ago
❯ tmux -V
tmux next-3.4
❯ kitty --version
kitty 0.31.0 created by Kovid Goyal
❯ cd ~/.local/share/nvim/lazy/image.nvim
❯ git rev-parse HEAD
ec577441edca399c43d77b522870dbd7b9cd38b8
❯ cat ~/.config/tmux/tmux.conf | grep allow -A1
set-option -gq allow-passthrough on
set -g visual-activity off 

minimal.lua:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--branch=stable",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
  {
    "3rd/image.nvim",
    event = "VeryLazy",
    dependencies = {
      {
        "nvim-treesitter/nvim-treesitter",
        build = ":TSUpdate",
        config = function()
          require("nvim-treesitter.configs").setup({
            ensure_installed = { "markdown" },
            highlight = { enable = true },
          })
        end,
      },
    },
    opts = {
      backend = "kitty",
      integrations = {
        markdown = {
          enabled = true,
          clear_in_insert_mode = false,
          download_remote_images = true,
          only_render_image_at_cursor = false,
          filetypes = { "markdown", "vimwiki" }, -- markdown extensions (ie. quarto) can go here
        },
        neorg = {
          enabled = true,
          clear_in_insert_mode = false,
          download_remote_images = true,
          only_render_image_at_cursor = false,
          filetypes = { "norg" },
        },
      },
      max_width = nil,
      max_height = nil,
      max_width_window_percentage = nil,
      max_height_window_percentage = 50,
      kitty_method = "normal",
      tmux_show_only_in_active_window = true,
    },
  },
})

package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?/init.lua;"
package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?.lua;"

vim.opt.number = true
vim.opt.conceallevel = 2
vim.opt.winbar = "image.nvim demo"
vim.opt.signcolumn = "yes:2"

local content = [[
# Hello World

![This is a remote image](https://gist.ro/s/remote.png)
]]

vim.schedule(function()
  local buf = vim.api.nvim_create_buf(false, true)
  vim.api.nvim_buf_set_lines(buf, 0, -1, true, vim.split(content, "\n"))
  vim.api.nvim_buf_set_option(buf, "filetype", "markdown")
  vim.api.nvim_set_current_buf(buf)
  vim.cmd("split")
end)

After running minimal lua with nvim --clean -c ":luafile minimal.lua", image is shown correctly but when I switch to another tmux window, the image will still be there. 20240102_14h20m20s_grim

3rd commented 9 months ago

That shouldn't happen, the new Tmux version might've broken our hack. It's working with Tmux 3.3a, I'll check with the new version and look for a different way to hook into some sort of window switch event. I'd hate to do polling, but that might be the last resort.

sahinakkaya commented 9 months ago

I skim through the documentation of kitty and I decided that using kitty with tmux is a crime. Kitty is capable of solving every problem I have with terminal emulators. (Images, ligatures, handling of keyboard and many more...) It is also capable of multiplexing. For anyone reading this, I encourage you to take some time to check what kitty is capable of. You don't need tmux.

3rd commented 9 months ago

Well, as much as I love Kovid, I don't agree with him on that, and I'd say that for me the multiplexer is more important than the terminal emulator.

Kitty is not capable of multiplexing. Multiplexing is not just being able to open multiple pseudoterms inside a terminal display.

Kitty has support for pre-configuring windows and panes on startup with --session, but that's all it does, they're not real sessions and the term probably makes things more confusing for some people, as actual sessions is the critical thing Kitty is not providing.

Of course it's not important for people that don't have terminal sessions deeply integrated into their workflow, and of course it's a hack. But, for me, it's an insane productivity booster I will never give up on.

sahinakkaya commented 9 months ago

Of course it's not important for people that don't have terminal sessions deeply integrated into their workflow

Yeah, for me this is the case. I don't use sessions that often. If I think I need sessions, I will try abduco. It is a dead project but might solve this issue.

liketoeatcheese commented 8 months ago

Hi @3rd, I'm also experiencing this issue and using tmux 3.3a. Switching windows works fine, but adding a new pane or switching to a different session will cause the issue. I'm wondering if this issue is still on the table to look at.

And 2nd you, I can't imagine a life without tmux

exosyphon commented 3 months ago

I started experiencing this as well. Has this been resolved and I need to bump versions of anything?

NVIM v0.10.0 tmux 3.4 image.nvim

3rd commented 3 months ago

Super weird, works fine for me on Neovim nightly and tmux 3.4, can you share your tmux config?

exosyphon commented 3 months ago

Of course!

# plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'janoamaral/tokyo-night-tmux'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'joshmedeski/t-smart-tmux-session-manager'
set -g @plugin 'fcsonline/tmux-thumbs'
set -gq allow-passthrough on

set -g status-left-length 30
setw -g mode-keys vi
set -g prefix C-a
unbind-key C-b

set-option -g prefix C-a
unbind-key C-a
bind-key C-a send-prefix

unbind [
bind Escape copy-mode
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
bind P paste-buffer
bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy"

bind r source-file ~/.tmux.conf \; display "Reloaded!"
bind | split-window -h
bind - split-window -v
# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h'  'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j'  'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k'  'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l'  'select-pane -R'
tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\'  'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\'  'select-pane -l'"

bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
bind N switch-client -l

set -g default-terminal "screen-256color"
set -g @continuum-restore 'on'
set -g status-interval 5
set -s escape-time 0
set -g base-index 1
setw -g pane-base-index 1
setw -g monitor-activity on
set -g visual-activity on
setw -g mouse on
set-option -g focus-events on
bind-key x kill-pane # skip "kill-pane 1? (y/n)" prompt
set -g detach-on-destroy off  # don't exit from tmux when closing a session
set -g @t-fzf-prompt '  ' # customize fzf prompt
set -g renumber-windows on   # renumber all windows when any window is closed
set -g history-limit 1000000 # increase history size (from 2,000)
set -g @t-bind "T"

run '~/.tmux/plugins/tpm/tpm'

set -g status-position top
# set -g status-style 'bg=#272727' # set to gruvbox background
set-option -g status-right ""  # Hide right status