Skip to content

Instantly share code, notes, and snippets.

@seandewar
Created July 19, 2023 22:42
Show Gist options
  • Save seandewar/819f437eb5f44ea4a766cb4d4841263e to your computer and use it in GitHub Desktop.
Save seandewar/819f437eb5f44ea4a766cb4d4841263e to your computer and use it in GitHub Desktop.
Neovim as a scrollback pager for Kitty. (Tested on Nvim 0.10)
-- Use Neovim as a scrollback pager for Kitty, allowing the
-- buffer to be manipulated as you wish. Configure as:
--
-- scrollback_pager nvim +'source <path to this script>.lua'
local api = vim.api
local orig_buf = api.nvim_get_current_buf()
local term_buf = api.nvim_create_buf(false, true)
api.nvim_set_current_buf(term_buf)
vim.bo.scrollback = 100000
local term_chan = api.nvim_open_term(0, {})
api.nvim_chan_send(term_chan, table.concat(api.nvim_buf_get_lines(orig_buf, 0, -1, true), "\r\n"))
vim.fn.chanclose(term_chan)
api.nvim_buf_set_lines(orig_buf, 0, -1, true, api.nvim_buf_get_lines(term_buf, 0, -1, true))
api.nvim_set_current_buf(orig_buf)
api.nvim_buf_delete(term_buf, { force = true })
vim.bo.modified = false
api.nvim_win_set_cursor(0, {api.nvim_buf_line_count(0), 0})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment