Disclaimer: Not a plugin!
TLDR: Made a Harpoon-like (or some might say “it’s just Global Marks”) feature using arglist with project and global persistence. Total lines of code: 261.
Hi guys, I am recently inspired by these posts:
Learnt about arglist from this source, and was so inspired to change to this arglist-based harpoon in my config. 1.
Previously, I was using a marks-based harpoon inspired from this source.
I will now describe my new solution:
Context:
For my current workflow, I mainly focus on working on…
Disclaimer: Not a plugin!
TLDR: Made a Harpoon-like (or some might say “it’s just Global Marks”) feature using arglist with project and global persistence. Total lines of code: 261.
Hi guys, I am recently inspired by these posts:
Learnt about arglist from this source, and was so inspired to change to this arglist-based harpoon in my config. 1.
Previously, I was using a marks-based harpoon inspired from this source.
I will now describe my new solution:
Context:
For my current workflow, I mainly focus on working on a singular file and then occasionally jumping to different files. This is why Harpoon workflow works for me. ThePrimeagean made a really good video explaining this concept which can be found here.
I am also in the process of slowly converting my config to use built-in features, and minimising the number of plugins to reduce my config’s plugin complexity. Hence, I won’t mention the use of the Harpoon plugin, though some might argue this is a plugin in its own right.
Problem with (2) marks-based harpoon
Pros:
Persistence across separate sessions due to the use of global marks
Cons:
Always jumping to specific location where you have marked it. But often times, when you jump back to the file, you want the cursor to be at where u last left the file.
As a result, you constantly need to remark the file which is troublesome, and runs the risk of u re-marking the wrong mark (e.g. mark to B instead of A (intended))
Problem with (1) arglist harpoon
Pros:
Remembers where you left the file
Cons:
No persistence across sessions. If you exit neovim, all your previously set arglist disappears.
Note: you need this autocommand for the arg-list harpoon to remember where you left the file.
-- go to last loc when opening a buffer
vim.api.nvim_create_autocmd('BufReadPost', {
desc = 'Go to last edit location when opening a new buffer',
group = vim.api.nvim_create_augroup('last_loc', { clear = true }),
callback = function(event)
local exclude = { 'gitcommit' }
local buf = event.buf
if vim.tbl_contains(exclude, vim.bo[buf].filetype) or vim.b[buf].last_loc_flag then
return
end
vim.b[buf].last_loc_flag = true
local mark = vim.api.nvim_buf_get_mark(buf, '"')
local lcount = vim.api.nvim_buf_line_count(buf)
if mark[1] > 0 and mark[1] <= lcount then
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end,
})
which i feel should be part of your autocommands anyways as it is very useful.
My solution
Project-specific arglist based on git repo. If there is no git repo, it will fallback to a global arglist. 1.
Remember where you left the file.
I hope yall find this useful. If you have any feedback, do let me know, as I am still trying to improve on writing my own config. I am also still trying this out so bugs are expected.