Update fzf lua markdown headings picker
This commit is contained in:
parent
d74bcda421
commit
5662825b99
1 changed files with 37 additions and 0 deletions
|
|
@ -48,3 +48,40 @@ local keymap = vim.keymap
|
|||
-- end
|
||||
--
|
||||
-- keymap.set("n", "<leader>fdh", markdown_headings, { desc = "Grep: Markdown headings" })
|
||||
|
||||
-- FZF lua headings picker
|
||||
local picker = require("fzf-lua")
|
||||
|
||||
local function fzf_lua_markdown_headings()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||
local headings = {}
|
||||
|
||||
for lnum, line in ipairs(lines) do
|
||||
local heading = line:match('^(#+%s+.+)$')
|
||||
if heading then
|
||||
vim.notify("Found heading: " .. heading, vim.log.levels.INFO)
|
||||
table.insert(headings, {
|
||||
lnum = lnum,
|
||||
text = heading,
|
||||
display = string.format("%4d: %s", lnum, heading)
|
||||
})
|
||||
end
|
||||
end
|
||||
picker.fzf_exec(function(fzf_cb)
|
||||
for _, heading in ipairs(headings) do
|
||||
fzf_cb(heading.display)
|
||||
end
|
||||
fzf_cb() -- EOF
|
||||
end, {
|
||||
prompt = "Markdown headings> ",
|
||||
actions = {
|
||||
['default'] = function(selected)
|
||||
local line_num = tonumber(selected[1]:match("%d+"))
|
||||
vim.api.nvim_win_set_cursor(0, { line_num, 0 })
|
||||
end
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
keymap.set("n", "<leader>fdh", fzf_lua_markdown_headings, { desc = "Grep: Markdown headings" })
|
||||
|
|
|
|||
Loading…
Reference in a new issue