pdfs part 2

This commit is contained in:
jannikdonker committed 2026-11-03 15:50:10 +01:00
1 parent f707596a5a
commit feda98c061
3 files changed
+5 -32

No files matched your search

-31
View File
@@ -1,31 +0,0 @@
-- PDF reader: Snacks.image already renders a PDF buffer (page 1) via
-- magick/gs in Ghostty. This adds page turning on top of it.
-- Open from Oil with <CR> like any file. In a PDF buffer:
-- n / N next / previous page {n}gp go to page n (gp = last page)
local function page_count(file)
local out = vim.fn.system({ "pdfinfo", file })
return tonumber(out:match("Pages:%s*(%d+)")) or 1
end
vim.api.nvim_create_autocmd("BufReadCmd", {
pattern = "*.pdf",
callback = function(ev)
local buf, file = ev.buf, vim.api.nvim_buf_get_name(ev.buf)
local pages, page = page_count(file), 1
local function show(n)
page = math.max(1, math.min(pages, n))
require("snacks.image.buf").attach(buf, { src = file .. "#page=" .. page })
vim.wo.statusline = ("%%f [%d/%d]"):format(page, pages)
end
vim.wo.statusline = ("%%f [1/%d]"):format(pages)
local function map(lhs, fn, desc)
vim.keymap.set("n", lhs, fn, { buffer = buf, desc = "PDF: " .. desc })
end
map("n", function() show(page + vim.v.count1) end, "next page")
map("N", function() show(page - vim.v.count1) end, "previous page")
map("gp", function() show(vim.v.count > 0 and vim.v.count or pages) end, "go to page (last if no count)")
end,
})
+5
View File
@@ -31,6 +31,7 @@ vim.pack.add({
{ src = "https://github.com/michaelrommel/nvim-silicon" },
{ src = "https://github.com/hat0uma/csvview.nvim.git" },
{ src = "https://github.com/folke/snacks.nvim" },
{ src = "https://github.com/r-pletnev/pdfreader.nvim" },
})
pcall(vim.cmd.colorscheme, "gruvbox")
@@ -105,6 +106,10 @@ require("snacks").setup({
terminal = {},
})
-- PDF reader (n/p page, z/q/e zoom, :PDFReader ...). Bookmark pickers need
-- telescope, which isn't installed; everything else works without it.
require("pdfreader").setup()
-- Toggle a bottom terminal panel (reuses the same shell instance).
vim.keymap.set({ "n", "t" }, "<leader>t",
function()