Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set mark at index N #617

Open
shellwhale opened this issue Jul 11, 2024 · 1 comment
Open

Set mark at index N #617

shellwhale opened this issue Jul 11, 2024 · 1 comment

Comments

@shellwhale
Copy link

shellwhale commented Jul 11, 2024

The docs show how to access the N mark.

vim.keymap.set("n", "<C-h>", function() harpoon:list():select(1) end)
vim.keymap.set("n", "<C-t>", function() harpoon:list():select(2) end)
vim.keymap.set("n", "<C-n>", function() harpoon:list():select(3) end)
vim.keymap.set("n", "<C-s>", function() harpoon:list():select(4) end)

But how do I set the N mark with a shortcut ? For example if I'd wanted to set the current file to be at index 3 I would do something like this :

vim.keymap.set("n", "<C-M-s>", function() harpoon:list():set(3) end)

Is that possible? I'm coming from vscode-harpoon and there was a nice command for it. I had setup like this

CTRL + ALT + 1 mark current file at index 1
CTRL + ALT + 2 mark current file at index 2
CTRL + ALT + 3 mark current file at index 3
...
ALT + 1 go to file at index 1
ALT + 2 go to file at index 2
ALT + 3 go to file at index 3

@shellwhale shellwhale changed the title Replace at index Set mark at index N Jul 11, 2024
@dc-jbw
Copy link

dc-jbw commented Jan 29, 2025

An old question, but here's a snippet from my own harpoon Lazy spec:

        -- NB: Using the replace methods can screw up the list if you don't 
        -- use them correclty; i.e., target a mark that actually exists.
        vim.keymap.set("n", "<leader>m1", function() harpoon:list():replace_at(1) end, { desc = "Set harpoon mark 1" })
        vim.keymap.set("n", "<leader>m2", function() harpoon:list():replace_at(2) end, { desc = "Set harpoon mark 2" })
        vim.keymap.set("n", "<leader>m3", function() harpoon:list():replace_at(3) end, { desc = "Set harpoon mark 3" })
        vim.keymap.set("n", "<leader>m4", function() harpoon:list():replace_at(4) end, { desc = "Set harpoon mark 4" })
        vim.keymap.set("n", "<leader>m5", function() harpoon:list():replace_at(5) end, { desc = "Set harpoon mark 5" })
        vim.keymap.set("n", "<leader>m6", function() harpoon:list():replace_at(6) end, { desc = "Set harpoon mark 6" })
        vim.keymap.set("n", "<leader>m7", function() harpoon:list():replace_at(7) end, { desc = "Set harpoon mark 7" })
        vim.keymap.set("n", "<leader>m8", function() harpoon:list():replace_at(8) end, { desc = "Set harpoon mark 8" })
        vim.keymap.set("n", "<leader>m9", function() harpoon:list():replace_at(9) end, { desc = "Set harpoon mark 9" })

Hopefully that answers your question. And as the comment suggests, harpoon will happily let you set marks at places in the list that don't exist yet, and it doesn't much like that, so use with caution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants