Skip to content

Instantly share code, notes, and snippets.

@eduardoarandah
Last active April 16, 2026 17:52
Show Gist options
  • Select an option

  • Save eduardoarandah/df68eb20168ecd7d2d0f795d84276dde to your computer and use it in GitHub Desktop.

Select an option

Save eduardoarandah/df68eb20168ecd7d2d0f795d84276dde to your computer and use it in GitHub Desktop.
Neovim plugin to browse tldr-pages cheatsheets directly from the editor
-- tldr.lua
-- Neovim command to browse tldr-pages cheatsheets directly from the editor
-- save as ~/.config/nvim/lua/tldr.lua
-- load with: require("tldr")
-- Commands:
-- :Tldr
-- :Tldr <topic>
vim.api.nvim_create_user_command("Tldr", function(args)
if args.args == "" then
local content = vim
.system({
"curl",
"-s",
"https://api.github.com/repos/tldr-pages/tldr/git/trees/fcef55edbc545d32e07dd4d29730cf70ff6a383e",
})
:wait()
local data = vim.json.decode(content.stdout)
local files = vim
.iter(data.tree)
:map(function(item)
return item.path:sub(0, -4)
end)
:totable()
vim.ui.select(files, { prompt = "Select a topic:" }, function(choice)
if choice then
vim.cmd("Tldr " .. choice)
end
end)
return
end
local query = args.args
local topic = "common"
local subtopic = query
if query:find("/") then
local parts = vim.split(query, "/")
topic = parts[1]
subtopic = parts[2]
end
vim.cmd("belowright vsplit")
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_win_set_buf(0, buf)
vim.cmd("r !curl -s https://raw.githubusercontent.com/tldr-pages/tldr/master/pages/" .. topic .. "/" .. subtopic .. ".md")
vim.bo[buf].filetype = "markdown"
vim.fn.cursor(1, 1)
vim.keymap.set("n", "q", "<cmd>bd<CR>", { buffer = buf, silent = true })
end, { nargs = "*" })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment