Last active
April 16, 2026 17:52
-
-
Save eduardoarandah/cf281383cef313d3f7a66a3b16563452 to your computer and use it in GitHub Desktop.
Neovim plugin to query cht.sh cheatsheets from within the editor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- cht_sh.lua | |
| -- Neovim command to query cht.sh cheatsheets from within the editor | |
| -- save as ~/.config/nvim/lua/cht_sh.lua | |
| -- load with: require("cht_sh") | |
| -- Commands: | |
| -- :Cht | |
| -- :Cht <topic> | |
| vim.api.nvim_create_user_command("Cht", function(args) | |
| if args.args == "" then | |
| local result = vim.system({ "curl", "-s", "https://cht.sh/:list" }):wait() | |
| local files = vim.split(result.stdout, "\n", { trimempty = true }) | |
| vim.ui.select(files, { prompt = "Select a cheatsheet:" }, function(choice) | |
| if choice then | |
| vim.cmd("Cht " .. choice) | |
| end | |
| end) | |
| return | |
| end | |
| local query = args.args:gsub(" ", "+") | |
| local result = vim.system({ "curl", "-s", "https://cht.sh/" .. query .. "?T" }):wait() | |
| local lines = vim.split(result.stdout, "\n", { trimempty = true }) | |
| vim.cmd("belowright vsplit") | |
| local buf = vim.api.nvim_create_buf(false, true) | |
| vim.api.nvim_win_set_buf(0, buf) | |
| vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) | |
| 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