mirror of
https://github.com/kogakure/dotfiles.git
synced 2026-02-03 20:25:30 +00:00
feat(nvim): add bookmarks plugin and custom fzf-lua picker
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
-- Vim bookmark plugin
|
||||
-- https://github.com/MattesGroeger/vim-bookmarks
|
||||
return {
|
||||
"MattesGroeger/vim-bookmarks",
|
||||
}
|
||||
28
config/nvim/lua/plugins/bookmarks.lua
Normal file
28
config/nvim/lua/plugins/bookmarks.lua
Normal 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,
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user