Skip to content

fix(terminal): prevent nvim crash on i in scrollback#103

Closed
qw457812 wants to merge 1 commit intofolke:mainfrom
qw457812:fix/term_scrollback
Closed

fix(terminal): prevent nvim crash on i in scrollback#103
qw457812 wants to merge 1 commit intofolke:mainfrom
qw457812:fix/term_scrollback

Conversation

@qw457812
Copy link
Copy Markdown
Contributor

@qw457812 qw457812 commented Oct 11, 2025

Description

Fixes nvim (both stable and nightly) exiting on i in scrollback with tmux.
:noautocmd startinsert in scrollback also crashes nvim.
Not sure why TermEnter doesn't work.

Versions:

nvim -v
NVIM v0.12.0-dev-1379+ga4006360f1
Build type: RelWithDebInfo
LuaJIT 2.1.1753364724
Run "nvim -V1 -v" for more info

tmux -V
tmux 3.5a

kitty --version
kitty 0.43.1 created by Kovid Goyal

macOS Sequola 15.5

Related Issue(s)

None

Screenshots

None

@folke
Copy link
Copy Markdown
Owner

folke commented Oct 11, 2025

What does this fix exactly? I don't have any issues with this.
In your case, can you just vim.schedule_wrap the original callback?

@qw457812
Copy link
Copy Markdown
Contributor Author

Sorry, I thought everyone can reproduce...

Type i in scrollback with latest commit:
side

Type i in scrollback with vim.schedule_wrap:

  vim.api.nvim_create_autocmd({ "TermEnter" }, {
    buffer = buf,
    callback = vim.schedule_wrap(function()
      vim.api.nvim_win_set_buf(self.win, self.buf)
      self:wo()
      if vim.api.nvim_buf_is_valid(buf) then
        pcall(vim.api.nvim_buf_delete, buf, { force = true })
      end
    end),
  })

side2

@folke folke closed this in 0bc6f88 Oct 11, 2025
@folke
Copy link
Copy Markdown
Owner

folke commented Oct 11, 2025

What you see is a Neovim segfault, so 100% a Neovim issue.
Your work-around is not great, but I just pushed some changes that hopefully work-around the issue you're seeing.

Can you check and let me know that fixes it?

@qw457812
Copy link
Copy Markdown
Contributor Author

qw457812 commented Oct 11, 2025

With vim.schedule_wrap, I found that some how TermLeave is triggered on i:

@qw457812
Copy link
Copy Markdown
Contributor Author

Great, fixed! Looks much cleaner. Thank you!

@qw457812 qw457812 deleted the fix/term_scrollback branch October 11, 2025 09:39
folke pushed a commit that referenced this pull request Oct 16, 2025
…ffer (#129)

## Description

After latest commits, the #103 issue is coming back. Nvim exit when I
press `i` in scrollback with tmux.

## Related Issue(s)

#103 

## Screenshots

Exactly the same as #103 's gif.
folke pushed a commit that referenced this pull request Oct 17, 2025
🤖 I have created a release *beep* *boop*
---


##
[2.0.0](v1.3.0...v2.0.0)
(2025-10-17)


### ⚠ BREAKING CHANGES

* **config:** changed the default keymaps. Please check the updated
documentation and example mappings

### Features

* **cli.claude:** transform line ranges to a format Claude can
understand. Closes
[#59](#59)
([4a492da](4a492da))
* **cli.select:** better distinction between attaching to
terminal/external
([48d0bf6](48d0bf6))
* **cli:** `close()` on an external session, now detaches from that
session. Closes [#98](#98)
([d2e6c64](d2e6c64))
* **cli:** added `<c-q>` to hide in normal mode, so from terminal double
`<c-q>` will hide
([358804c](358804c))
* **cli:** added health checks and optional reqs to the docs for `lsof`
and `ps`. Fixes [#89](#89)
([d403ec3](d403ec3))
* **cli:** added some config option validation
([c236b38](c236b38))
* **cli:** added terminal navigation with `<c-hjkl>`. Only mapped when
not a float and a window in the dir exists. See
[#51](#51)
([b48e177](b48e177))
* **cli:** deduplicate cli tool sessions. Closes
[#92](#92)
([e5bcf17](e5bcf17))
* **cli:** handle special filenames for Claude, Gemini, Qwen. Fixes
[#130](#130)
([19b5985](19b5985))
* **config:** changed the default keymaps. Please check the updated
documentation and example mappings
([6608705](6608705))
* **context:** you can now use context fallbacks like `{function|line}`
([076147a](076147a))
* **copilot:** allow configuring minimum level for copilot LSP messages
([4b6750b](4b6750b))
* **opencode:** add pid to external opencode sessions
([3d9d519](3d9d519))
* **terminal:** much better scrollback buffer. no flickering and should
work in all modes
([3aa2fe5](3aa2fe5))
* **terminal:** restore normal/terminal mode when entering the sidekick
window
([50c40d5](50c40d5))
* **terminal:** switch to scrollback when doing mouse scroll
([0dd3c3b](0dd3c3b))
* **tmux:** entering normal mode in a tmux terminal, now loads the whole
tmux scrollback
([a453f76](a453f76))
* **tmux:** some tools won't process input if they don't have focus, so
tools can now set `mux_focus = true`
([41dec4d](41dec4d))
* **tool:** tools can now further format text before it's sent. See
[#130](#130), see
[#59](#59)
([28f8a07](28f8a07))
* **util:** weak ref util method
([8036aea](8036aea))


### Bug Fixes

* **cli.prompt:** proper way of rendering templates with highlights
([30b7b9e](30b7b9e))
* **cli.select:** sort terminal sessions before external sessions
([c487d53](c487d53))
* **cli.state:** allow creating new sessions for tools that have only
external sessions
([c588efb](c588efb))
* **cli:** allow sending a newlline `msg="\n"`
([fc0067a](fc0067a))
* **cli:** don't send empty messages
([63f626c](63f626c))
* **location:** different format that should work for most cli tools.
Closes [#59](#59)
([d570e1f](d570e1f))
* **nes:** added triggerKind. Maybe that's needed for nes?
([e535808](e535808))
* **nes:** better didFocus tracking
([3669eae](3669eae))
* **nes:** don't clear NES on `TextChanged` or `BufWritePre`. Closes
[#91](#91)
([32fa55c](32fa55c))
* **nes:** don't process unloaded buffers. Closes
[#86](#86)
([620adf0](620adf0))
* **nes:** exec nes commands AFTER edits have been applied
([80d1604](80d1604))
* **nes:** skip old edits early
([8395007](8395007))
* **nes:** textDocument/didFocus
([b7085d7](b7085d7))
* **nes:** trigger on `ModeChanged *:n` instead of `InsertLeave`. See
[#125](#125)
([abbd051](abbd051))
* **opencode:** check that open server is actually from an opencode
process. Closes [#87](#87)
([cb8485a](cb8485a))
* **procs:** handle case where `USER` is not set. Closes
[#82](#82)
([01f89b7](01f89b7))
* **q:** filer procs on qchat instead of `q`, which seems to be the
actual binary. Closes
[#80](#80)
([4b65b8a](4b65b8a))
* **qwen:** set `mux_focus = true` since qwen doesnt process input if
unfocused. Fixes
[#104](#104)
([c262b25](c262b25))
* **sessions:** load tools during session setup, since thet may register
session backends (like opencode)
([c7761eb](c7761eb))
* **status:** always return `nil` when copilot status is disabled in
config
([f908fec](f908fec))
* **terminal:** allow auto split width/height
([#111](#111))
([03cf9fb](03cf9fb))
* **terminal:** better handling of crlf for send. See
[#119](#119)
([7185e08](7185e08))
* **terminal:** blur on hide
([81b2a85](81b2a85))
* **terminal:** cleanup scrollback buffer
([9ef38db](9ef38db))
* **terminal:** don't error when it's the last window and hiding. Closes
[#124](#124)
([cab3ec4](cab3ec4))
* **terminal:** keymap rhs fallback to rhs string
([2b644f0](2b644f0))
* **terminal:** no need to check for mouse scroll when we're not in
terminal mode
([b52c3be](b52c3be))
* **terminal:** only show scrollback when entering normal mode and the
terminal window is current. Closes
[#106](#106)
([1e03666](1e03666))
* **terminal:** remove padding since it causes issues with terminal
reflow (Neovim bug)
([cc32068](cc32068))
* **terminal:** safer way of entering terminal mode from scrollback
buffer ([#129](#129))
([2195213](2195213))
* **terminal:** safer way of entering terminal mode from scrollback
buffer. Closes [#103](#103)
([0bc6f88](0bc6f88))
* **terminal:** scroll to last line in normal mode. Closes
[#101](#101)
([69eb7b7](69eb7b7))
* **terminal:** send all text in one chunk with nvim_paste. Fixes
[#119](#119). Fixes
[#118](#118)
([ca97ecd](ca97ecd))
* **terminal:** use `nvim_paste` instead of `nvim_chan_send` to better
simulate user input. Closes
[#110](#110)
([cebcd44](cebcd44))
* **terminal:** use nvim_put directly to paste into the terminal
([bed1d65](bed1d65))
* **text:** handle empty virtual lines
([98a33eb](98a33eb))
* **tmux:** use `paste-buffer` with the `-r` flag to preserve newlines.
Fixes [#93](#93)
([2fdc4d4](2fdc4d4))
* **zellij:** attach to existing isolated session
([9deb771](9deb771))
* **zellij:** zellij:create -&gt; zellij:start
([4bd0df2](4bd0df2))


### Performance Improvements

* **nes:** only send didFocus events for regular buffers and if
different
([39a1638](39a1638))
* **terminal:** only load scrollback buffer when needed
([628c3d0](628c3d0))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

2 participants