Skip to content

feat: vterm preview#2558

Merged
ibhagwan merged 5 commits intoibhagwan:mainfrom
phanen:vterm-preview
Feb 14, 2026
Merged

feat: vterm preview#2558
ibhagwan merged 5 commits intoibhagwan:mainfrom
phanen:vterm-preview

Conversation

@phanen
Copy link
Copy Markdown
Collaborator

@phanen phanen commented Feb 8, 2026

No description provided.

@ibhagwan
Copy link
Copy Markdown
Owner

ibhagwan commented Feb 8, 2026

Can this also replace chafa/viu/ueberzugpp?

@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented Feb 8, 2026

I tried but looks bad, builtin terminal don't seem support them well.

require("fzf-lua").fzf_exec("seq 100", {
	winopts = { preview = { winopts = { winbl = 0 } } },
	previewer = {
		_ctor = function()
			local p = require("fzf-lua.previewer.builtin").buffer_or_file:extend()
			function p:parse_entry(entry)
				return {
					cmd = {
						"sh",
						"-c",
						-- "fd . --color=always $VIMRUNTIME | head -30",
						-- "chafa $VIMRUNTIME/nvim.png",
						"viu $VIMRUNTIME/neovim.ico",
					},
				}
			end
			return p
		end,
	},
})

@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented Feb 10, 2026

fd --color=always issue fixed in neovim/neovim#37791.

@ibhagwan
Copy link
Copy Markdown
Owner

fd --color=always issue fixed in neovim/neovim#37791.

Nice, so we can merge this soon with limit to nightly?

@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented Feb 10, 2026

Nice, so we can merge this soon with limit to nightly?

Most of time it work well even not on nightly.
There're other possible issues...happened when we preview other instance's screenshots (when the instance open a terminal/fzf?).

Also have some flicker issue when change current preview entry.

@phanen phanen force-pushed the vterm-preview branch 3 times, most recently from a80d2c4 to 0c65f22 Compare February 13, 2026 04:52
opts.previewer.nvim_server2 = { vterm = true, _ctor = require('fzf-lua.previewer').fzf.nvim_server }
opts.serverlist.previewer = 'nvim_server2'

fix(preview): avoid vterm flicker (set_buf before term_open/chan_send)

fix(preview): open_term for string[] content previewer
@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented Feb 13, 2026

Terminal buffer cannot scroll from fzf win, maybe related to neovim/neovim#4895 (comment). This hack can make it work.

vim.cmd([[hor below pedit tmp]])
local win = vim.fn.win_getid(vim.fn.winnr("j"))
local term_preview = function(cmd)
	local newbuf = api.nvim_create_buf(false, true)
	-- vim.api.nvim_buf_call(newbuf, function()
	-- 	vim.fn.jobstart(cmd, {
	-- 		term = true,
	-- 		on_exit = function()
	-- 			vim._with({ noautocmd = true }, function()
	-- 				api.nvim_win_set_buf(win, newbuf)
	-- 			end)
	-- 		end,
	-- 	})
	-- end)
	api.nvim_buf_call(newbuf, function()
		vim.cmd([[noau 0r! ]] .. cmd)
		-- api.nvim_create_autocmd("ChanOpen", {
		-- 	buffer = newbuf,
		-- 	once = true,
		-- 	callback = function() end,
		-- })
		api.nvim_open_term(newbuf, {})
		vim.schedule(function()
			api.nvim_win_set_buf(win, newbuf)
		end)
	end)
end
local new = function()
	term_preview("fd --color=always . " .. vim.env.VIMRUNTIME)
end
local scroll_down = function()
	local curwin = api.nvim_get_current_win()
	vim.api.nvim_set_current_win(win)
	vim.defer_fn(function()
		vim.api.nvim_feedkeys("", "nt", false)
		vim.defer_fn(function()
			vim.api.nvim_set_current_win(curwin)
		end, 30)
	end, 30)
end
vim.keymap.set("n", "<c-j>", new)
vim.keymap.set("n", "<c-d>", scroll_down)

stopinsert -> schedule -> scorll -> startinsert
@phanen phanen marked this pull request as ready for review February 13, 2026 16:46
@ibhagwan
Copy link
Copy Markdown
Owner

You marked this ready, shall I merge?

sometime it don't seem correct, but should better than none
@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented Feb 14, 2026

Yeah, I think it's ready for merge.
Builtin term is not better than fzf builtin preview most of the time.

@ibhagwan
Copy link
Copy Markdown
Owner

Yeah, I think it's ready for merge. Builtin term is not better than fzf builtin preview most of the time.

So for now we keep it just as a backup previewer?

@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented Feb 14, 2026

Yes. Can switch by: previewers.bat.vterm=true, FzfLua live_grep previewer=bat.

@ibhagwan
Copy link
Copy Markdown
Owner

Ty @phanen!

@ibhagwan ibhagwan merged commit 5921997 into ibhagwan:main Feb 14, 2026
8 checks passed
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