Neovim froze in Insert mode waiting for tmux list-panes

On a remote machine, Neovim stopped responding when I entered Insert mode inside tmux. I was running Neovim 0.10.2 with LazyVim, nvim-cmp, and cmp-tmux, which suggests words from other tmux panes.

The frozen editor was waiting for tmux list-panes. Removing just cmp-tmux fixed the freeze. The other completion sources stayed enabled.

Ask the frozen process what it is waiting for

Instead of restarting the frozen editor, I inspected it from a second shell on the same machine:

1
2
3
ps -u "$USER" -o pid,ppid,stat,wchan:24,args | grep -E '[n]vim'
# Use the PID of the editor process (the --embed child if there are two).
ps --ppid 43971 -o pid,ppid,stat,wchan:24,args

The relevant lines from the process listing (columns trimmed):

1
2
3
  PID  PPID WCHAN                 COMMAND
43971 43970 pipe_wait             nvim --embed nord-status-content.conf
44758 43971 poll_schedule_timeout tmux list-panes -F #{pane_id} -a

Process listing showing Neovim in pipe_wait and its tmux list-panes child

Rendered excerpt of the process listing. The PPID on the boxed line matches the PID of the blocked Neovim process.

The parent-child relationship was the first clue. The file descriptor listing made the connection: the tmux client’s stdout and one of Neovim’s read descriptors pointed to the same pipe. Neovim was stuck reading from it.

Why a completion source could freeze the editor

The cmp-tmux source calls get_panes() to find panes to scan. I had all_panes = true, so it added -a to tmux list-panes -F '#{pane_id}'. The blocking part is in lua/cmp_tmux/tmux.lua, before the plugin starts any asynchronous jobs to capture pane contents:

1
2
3
4
5
local handle = io.popen(cmd)
if handle ~= nil then
    local data = handle:read('*all')
    -- Parse the pane IDs, then close the handle.
end

read('*all') waits for end-of-file. If the tmux client doesn’t finish, that read holds up Neovim’s main loop. Completion made the whole editor look frozen, not just the popup menu.

A fresh request from another shell did return later:

1
timeout 2s tmux list-panes -F '#{pane_id}' -a

That check showed tmux could answer a new request. It didn’t explain why the original client stalled, and I didn’t need to solve that to remove the blocking call from my editor.

Workaround: skip tmux completion for one launch

1
env -u TMUX nvim path/to/file

cmp-tmux checks for the TMUX environment variable. Unsetting it for this launch makes the plugin skip pane completion without changing the parent shell or any config files. This won’t unfreeze an existing editor, and other tmux-aware features in the new process may behave differently too.

Fix: remove only the tmux source

My setup builds on the nvim-cmp configuration. On the affected machine I backed up the active spec before editing it:

1
2
config="$HOME/.config/nvim/lua/plugins/nvim-cmp.lua"
cp -p -- "$config" "$config.bak.$(date +%Y%m%d)"

In ~/.config/nvim/lua/plugins/nvim-cmp.lua, I removed two things:

  1. 'andersevenrud/cmp-tmux', from the nvim-cmp dependencies.
  2. The name = 'tmux' source and its options from cmp.config.sources(...). It was the only source in the last group, so I removed that group and the comma that had separated it from the previous one.

Then I opened a fresh Neovim session. I didn’t need to restart tmux, change terminal settings, or turn off nvim-cmp.

Verify that Insert mode and completion still work

To check the active source list in a fresh editor, first load the plugin, then print its sources:

1
2
:Lazy! load nvim-cmp
:lua print(vim.inspect(vim.tbl_map(function(s) return s.name end, require('cmp').get_config().sources)))
1
{ "nvim_lsp", "nvim_lua", "luasnip", "buffer", "path", "neorg", "orgmode", "dotenv" }

The new config passed a Lua syntax check. With TMUX set and nvim-cmp loaded, a fresh headless Neovim processed i followed by test text and reported Mode: i; buffer: insertmodetest. Reopening Neovim in the normal terminal session fixed the original symptom too.

The only feature I lost was suggestions from other tmux panes. If the whole editor stops responding during completion, check its child processes before disabling every plugin: a single synchronous call can make an otherwise healthy editor look dead.

相关内容

william 支付宝支付宝
william 微信微信
0%