[nvim] Add cheatsheet.nvim and a its picker for fzf-lua
This commit is contained in:
1 parent
1b7517ee21
commit
0b4b5c653c
2 files changed
+76
-1
No files matched your search
@@ -2,6 +2,7 @@
|
|||||||
"FixCursorHold.nvim": { "branch": "master", "commit": "1900f89dc17c603eec29960f57c00bd9ae696495" },
|
"FixCursorHold.nvim": { "branch": "master", "commit": "1900f89dc17c603eec29960f57c00bd9ae696495" },
|
||||||
"blink.cmp": { "branch": "main", "commit": "78336bc89ee5365633bcf754d93df01678b5c08f" },
|
"blink.cmp": { "branch": "main", "commit": "78336bc89ee5365633bcf754d93df01678b5c08f" },
|
||||||
"bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" },
|
"bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" },
|
||||||
|
"cheatsheet.nvim": { "branch": "master", "commit": "6a5c69d42013331a3eda70b340378f2f912b9a90" },
|
||||||
"conform.nvim": { "branch": "master", "commit": "016802de402556da54c36bd7359b441266b01cdd" },
|
"conform.nvim": { "branch": "master", "commit": "016802de402556da54c36bd7359b441266b01cdd" },
|
||||||
"diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" },
|
"diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" },
|
||||||
"easy-dotnet.nvim": { "branch": "main", "commit": "e698b942a0a91cd5b457b828d16a66b7cb94d732" },
|
"easy-dotnet.nvim": { "branch": "main", "commit": "e698b942a0a91cd5b457b828d16a66b7cb94d732" },
|
||||||
|
|||||||
@@ -10,9 +10,78 @@ local function search_in_root()
|
|||||||
return vim.fn.getcwd()
|
return vim.fn.getcwd()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function parse_cheatsheet(path)
|
||||||
|
local cheats = {}
|
||||||
|
if vim.fn.filereadable(path) ~= 1 then return cheats end
|
||||||
|
for _, line in ipairs(vim.fn.readfile(path)) do
|
||||||
|
line = vim.trim(line)
|
||||||
|
if line ~= "" and not vim.startswith(line, "#") then
|
||||||
|
local desc, code = line:match("^(.-)%s*|%s*(.+)$")
|
||||||
|
if desc and code then
|
||||||
|
table.insert(cheats, { desc, code })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return cheats
|
||||||
|
end
|
||||||
|
|
||||||
|
local function command_palette()
|
||||||
|
local fzf = require("fzf-lua")
|
||||||
|
local plugin = require("lazy.core.config").plugins["cheatsheet.nvim"]
|
||||||
|
local sources = {
|
||||||
|
vim.fn.stdpath("config") .. "/cheatsheet.txt",
|
||||||
|
}
|
||||||
|
|
||||||
|
if plugin then
|
||||||
|
table.insert(sources, plugin.dir .. "/cheatsheets/cheatsheet-default.txt")
|
||||||
|
end
|
||||||
|
|
||||||
|
local lines, lookup = {}, {}
|
||||||
|
for _, path in ipairs(sources) do
|
||||||
|
for _, cheat in ipairs(parse_cheatsheet(path)) do
|
||||||
|
local line = string.format("%-50s %s", cheat[1], cheat[2])
|
||||||
|
if not lookup[line] then
|
||||||
|
table.insert(lines, line)
|
||||||
|
lookup[line] = cheat[2]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function cmdline_part(code)
|
||||||
|
return code:match("^:([^%[{]*)")
|
||||||
|
end
|
||||||
|
|
||||||
|
fzf.fzf_exec(lines, {
|
||||||
|
prompt = "Cheats> ",
|
||||||
|
winopts = { fullscreen = false, height = 0.5, width = 0.7 },
|
||||||
|
actions = {
|
||||||
|
["default"] = function(sel)
|
||||||
|
local code = sel and lookup[sel[1]]
|
||||||
|
if not code then return end
|
||||||
|
local cmd = cmdline_part(code)
|
||||||
|
if cmd then
|
||||||
|
vim.api.nvim_feedkeys(":" .. cmd, "n", false)
|
||||||
|
else
|
||||||
|
vim.fn.setreg("+", code)
|
||||||
|
vim.notify("Copied: " .. code)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
-- Alt-Enter: execute immediately (only for plain commands)
|
||||||
|
["alt-enter"] = function(sel)
|
||||||
|
local code = sel and lookup[sel[1]]
|
||||||
|
local cmd = code and cmdline_part(code)
|
||||||
|
if cmd then vim.cmd(cmd) end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"ibhagwan/fzf-lua",
|
"ibhagwan/fzf-lua",
|
||||||
dependencies = { "nvim-tree/nvim-web-devicons" },
|
dependencies = {
|
||||||
|
{ "nvim-tree/nvim-web-devicons" },
|
||||||
|
{ "doctorfree/cheatsheet.nvim", lazy = true }
|
||||||
|
},
|
||||||
opts = {
|
opts = {
|
||||||
winopts = {
|
winopts = {
|
||||||
fullscreen = true,
|
fullscreen = true,
|
||||||
@@ -130,5 +199,10 @@ return {
|
|||||||
end,
|
end,
|
||||||
desc = "Live grep the current buffer",
|
desc = "Live grep the current buffer",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"<leader>fp",
|
||||||
|
command_palette,
|
||||||
|
desc = "Find command",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user