feat(nvim): add bookmarks plugin and custom fzf-lua picker

This commit is contained in:
Stefan Imhoff
2024-12-29 10:23:21 +01:00
parent 6a7a709281
commit b368b600ff
4 changed files with 96 additions and 9 deletions

View File

@@ -11,6 +11,7 @@
"blamer.nvim": { "branch": "master", "commit": "e0d43c11697300eb68f00d69df8b87deb0bf52dc" },
"blink-cmp-copilot": { "branch": "main", "commit": "c5c5cbce5748d21073f1d5348a92ebe6ce63f387" },
"blink.cmp": { "branch": "main", "commit": "5f442681df24fe705d1ee7ce5b4d435aa4b4dee4" },
"bookmarks.nvim": { "branch": "main", "commit": "0540d52ba64d0ec7677ec1ef14b3624c95a2aaba" },
"bufferline.nvim": { "branch": "main", "commit": "261a72b90d6db4ed8014f7bda976bcdc9dd7ce76" },
"catppuccin": { "branch": "main", "commit": "f67b886d65a029f12ffa298701fb8f1efd89295d" },
"chafa.nvim": { "branch": "main", "commit": "792c8f4f0e86b5e27c3602be4614f886f3a12a5a" },
@@ -50,7 +51,6 @@
"lualine.nvim": { "branch": "master", "commit": "2a5bae925481f999263d6f5ed8361baef8df4f83" },
"lush.nvim": { "branch": "main", "commit": "45a79ec4acb5af783a6a29673a999ce37f00497e" },
"markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" },
"marks.nvim": { "branch": "master", "commit": "bb25ae3f65f504379e3d08c8a02560b76eaf91e8" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "c6c686781f9841d855bf1b926e10aa5e19430a38" },
"mason-nvim-dap.nvim": { "branch": "main", "commit": "8b9363d83b5d779813cdd2819b8308651cec2a09" },
"mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
@@ -126,7 +126,6 @@
"twilight.nvim": { "branch": "main", "commit": "1584c0b0a979b71fd86b18d302ba84e9aba85b1b" },
"vim-abolish": { "branch": "master", "commit": "dcbfe065297d31823561ba787f51056c147aa682" },
"vim-astro": { "branch": "main", "commit": "9b4674ecfe1dd84b5fb9b4de1653975de6e8e2e1" },
"vim-bookmarks": { "branch": "master", "commit": "9cc5fa7ecc23b052bd524d07c85356c64b92aeef" },
"vim-fugitive": { "branch": "master", "commit": "fcb4db52e7f65b95705aa58f0f2df1312c1f2df2" },
"vim-gh-line": { "branch": "master", "commit": "731751fdfa4f64a061dbc7088cb7b2f12e0828ad" },
"vim-grammarous": { "branch": "master", "commit": "db46357465ce587d5325e816235b5e92415f8c05" },

View File

@@ -1,5 +0,0 @@
-- Vim bookmark plugin
-- https://github.com/MattesGroeger/vim-bookmarks
return {
"MattesGroeger/vim-bookmarks",
}

View File

@@ -0,0 +1,28 @@
-- A Bookmarks Plugin With Global File Store For Neovim Written In Lua.
-- https://github.com/tomasky/bookmarks.nvim
return {
"tomasky/bookmarks.nvim",
event = "VimEnter",
config = function()
require("bookmarks").setup({
save_file = vim.fn.expand("$HOME/.bookmarks"), -- bookmarks save file path
keywords = {
["@t"] = "", -- mark annotation startswith @t ,signs this icon as `Todo`
["@w"] = "", -- mark annotation startswith @w ,signs this icon as `Warn`
["@f"] = "", -- mark annotation startswith @f ,signs this icon as `Fix`
["@n"] = "󱇗", -- mark annotation startswith @n ,signs this icon as `Note`
},
on_attach = function(bufnr)
local bm = require("bookmarks")
local map = vim.keymap.set
map("n", "mm", bm.bookmark_toggle) -- add or remove bookmark at current line
map("n", "mi", bm.bookmark_ann) -- add or edit mark annotation at current line
map("n", "mc", bm.bookmark_clean) -- clean all marks in local buffer
map("n", "mn", bm.bookmark_next) -- jump to next mark in local buffer
map("n", "mp", bm.bookmark_prev) -- jump to previous mark in local buffer
map("n", "ml", bm.bookmark_list) -- show marked file list in quickfix window
map("n", "mx", bm.bookmark_clear_all) -- removes all bookmarks
end,
})
end,
}

View File

@@ -2,7 +2,10 @@
-- https://github.com/ibhagwan/fzf-lua
return {
"ibhagwan/fzf-lua",
dependencies = { "nvim-tree/nvim-web-devicons" },
dependencies = {
"nvim-tree/nvim-web-devicons",
"tomasky/bookmarks.nvim",
},
keys = {
{ ";R", "<cmd>FzfLua oldfiles<cr>", desc = "Recently used" },
{ ";a", "<cmd>FzfLua files --hidden<cr>", desc = "Find Files (hidden)" },
@@ -10,10 +13,72 @@ return {
{ ";cs", "<cmd>FzfLua spell_suggest<cr>", desc = "Spell Suggest" },
{ ";d", "<cmd>FzfLua diagnostics_workspace<cr>", desc = "Diagnostics" },
{ ";f", "<cmd>FzfLua files<cr>", desc = "Find Files" },
{ ";m", "<cmd>lua require('fzf-lua').bookmarks({ path_shorten = true })<cr>", desc = "Bookmarks" },
{ ";r", "<cmd>FzfLua resume<cr>", desc = "Resume" },
{ "<C-p>", "<cmd>FzfLua files<cr>", desc = "Find Files" },
{ "<C-t>", "<cmd>FzfLua<cr>", desc = "Telescope" },
{ "<M-p>", "<cmd>FzfLua files --hidden<cr>", desc = "Find Files (hidden)" },
},
opts = {},
config = function()
local fzf = require("fzf-lua")
local config = require("bookmarks.config").config
local function get_text(annotation)
local pref = string.sub(annotation, 1, 2)
local ret = config.keywords[pref]
if ret == nil then
ret = config.signs.ann.text .. " "
end
return ret .. annotation
end
-- Register the custom bookmarks picker
fzf.bookmarks = function(opts)
opts = opts or {}
-- Get bookmarks from cache
local allmarks = config.cache.data
local results = {}
for filename, marks in pairs(allmarks) do
local display_path = filename
if opts.path_shorten then
-- Get path relative to current working directory
display_path = vim.fn.fnamemodify(filename, ":~:.")
end
for lnum, mark in pairs(marks) do
local text = mark.a and get_text(mark.a) or mark.m
table.insert(results, string.format("%s:%s:%s", display_path, lnum, text))
end
end
-- Call fzf-lua with the collected data
return fzf.fzf_exec(results, {
prompt = "Bookmarks> ",
actions = {
["default"] = function(selected)
local parts = vim.split(selected[1], ":", { plain = true })
if parts[1] then
-- Expand the path back to full path
local full_path = vim.fn.fnamemodify(parts[1], ":p")
-- Open file and jump to line
vim.cmd("edit " .. vim.fn.fnameescape(full_path))
if parts[2] then
vim.cmd(parts[2])
end
end
end,
},
previewer = true,
fzf_opts = {
["--delimiter"] = ":",
["--with-nth"] = "1,2,3",
},
})
end
-- Setup fzf-lua with default options
fzf.setup({})
end,
}