bookmarks.nvim
bookmarks.nvim copied to clipboard
Add scoped bookmarks
Fixes: #7
Something to consider is if we should make scoped the default, or keep the current global behavior.
What do you think @tomasky?
From what I've seen most other plugins do per-cwd state, such as harpoon, neogit, and likely a few others
I tried this feature branch, and if scoped
is set to false, an error will occur
Thank you :heart:
I will have a look at it
Alright, I should have fixed your issue now
So good! This is working for me. It breaks the telescope extension though.
Setting scope to false
doesn't return an error, however when returning the bookmarks in the quick fix window, I still only see the scoped bookmarks, and not all (ie globally)
require('bookmarks').setup {
-- sign_priority = 8, --set bookmark sign priority to cover other sign
scoped = false,
save_file = vim.fn.expand "$HOME/.config/nvim/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
end
}
There is a global bookmark file too
bookmarks
├── %%global%%
├── %Users%tjex%.config%nvim
└── %Users%tjex%.local%src%zk-org%zk.git%main
I see, would you want the global and scope bookmarks to coexist and be loaded at the same time?
For now, it is just one or the other as a means for the user to make one decision of their preference initially.
Would you like them to coexist? if so, how would creating a bookmark behave and when or how would you want it to decide for where to store it?
I think it can be useful to have the option to switch between global and scoped mode, even by means of switching scoped = <bool>
and restarting neovim or sourcing the config file.
I see it as a similar UX to browser bookmarks, where you can store a bookmark in a folder, which keeps it available through the context of that folder name, but we can also search globally for it directly in the address bar.
I think there may be more value in appending all bookmarks added to the global file, even when in scoped mode. That way, we can start in global mode and be able to jump around everywhere, or start in scoped mode and navigate to each root directory to then work.
Although, I do see the issue with that, in that the global bookmark file will become bloated.
Perhaps there could be a keybind that specifically adds a bookmark to the global file, even when in scoped mode?
That way, even in scoped mode, we can make an executive decision that we would like to be able to access this document from anywhere. This would keep the global bookmark file clean, while also maintaining some value / possibility to switch back to a global mode in the future if we want to.
If it had to be one or the other though, I would agree that scoped bookmarks are more valuable.
Personally, I think I prefer the clean separation between scoped and global bookmarks. With a ton of scoped bookmarks, I would rather not have them pollute the global ones.
That being said, I think this PR providing scoped bookmarks is a huge improvement over the default workflow. I would rather see this being merged sooner rather than later, and further improvements can be made with subsequent PRs, if needed.
Hoping @tomasky can give it a quick look for review.
Alright, I should have fixed your issue now
May I ask why change session does not isolate bookmarks from different CWDs? It only works when starting nvim from different directories, but my cwd also changed with the session change. But harpoon works fine, I tryed vim-bookmark and still the same.
tested, using your branch, thanks a lot @tomasky merge please
Thanks for providing this "scoped bookmarks" feature.
It also requires a change to the config (example):
save_file = vim.fn.expand("$HOME/.bookmarks"), -- this causes an error (see below)
save_file = ".bookmarks", -- bookmarks save file path
Error message:
Error executing luv callback:
...share/nvim/lazy/bookmarks.nvim/lua/bookmarks/actions.lua:240: bookmarks.save_file must be a directory
stack traceback:
[C]: in function 'assert'
...share/nvim/lazy/bookmarks.nvim/lua/bookmarks/actions.lua:240: in function <...share/nvim/lazy/bookmarks.nvim/lua/bookmarks/actions.lua:227>
I also prefer scoped = true,
as a default, as jumping to global uppercase marks or bookmarks can cause "swap file already exist" warnings if the target file is already open in another vim instance.