ThePrimeagen / neovimrc

354 stars 33 forks source link

How can I use this? #5

Closed Jeremy5909 closed 2 months ago

Jeremy5909 commented 4 months ago

Sorry I'm a beginner

I understand that git cloning doesn't work (at least without modification) because

Failed to run `config` for harpoon

.../../.config/nvim/lua/theprimeagen/lazy/local.lua:7: module 'harpoon' not found:
^Ino field package.preload['harpoon']
cache_loader: module harpoon not found
cache_loader_lib: module harpoon not found
^Ino file './harpoon.lua'
^Ino file '/opt/homebrew/share/luajit-2.1/harpoon.lua'
^Ino file '/usr/local/share/lua/5.1/harpoon.lua'
^Ino file '/usr/local/share/lua/5.1/harpoon/init.lua'
^Ino file '/opt/homebrew/share/lua/5.1/harpoon.lua'
^Ino file '/opt/homebrew/share/lua/5.1/harpoon/init.lua'
^Ino file './harpoon.so'
^Ino file '/usr/local/lib/lua/5.1/harpoon.so'
^Ino file '/opt/homebrew/lib/lua/5.1/harpoon.so'
^Ino file '/usr/local/lib/lua/5.1/loadall.so'

# stacktrace:
  - lua/theprimeagen/lazy/local.lua:7 _in_ **config**
  - lua/theprimeagen/lazy_init.lua:14
  - lua/theprimeagen/init.lua:4
  - init.lua:1

How can I fix this?

tabedzki commented 4 months ago

@Jeremy5909 I did some digging into the code itself.

How I found what was wrong

Looking at the logs, we can see that this issue is related to a missing package called harpoon. Let's open up the file ~/.config/nvim/lua/theprimeagen/lazy/local.lua we examine what is going on around line 7.

Why it doesn't work out of the box

Opening up local.lua, we see the reason why this doesn't work out of the box is a reference to a local directory ~/personal/harpoonhere. Therefore, the program looks for a local installation of harpoon.

As Prime is the developer for harpoon, he likely has it installed locally as he develops the code and keeps it in a directory structure as demonstrated here.

What we need to do is put harpoon where the configuration is looking. As the master branch of harpoon is deprecated (seen here), you will need to install the harpoon2 branch of that repository.

How to get the code working

  1. If you haven't already, git clone this repo into ~/.config/nvim by doing git clone https://github.com/ThePrimeagen/neovimrc.git ~/.config/nvim
  2. Now that you have Prime's neovimrc in the right place, do git clone https://github.com/ThePrimeagen/harpoon.git ~/personal/harpoon -b harpoon2.
    • The -b flag denotes that we should be checking out the harpoon2 branch directly instead of master

Now you should be able to use Prime's Harpoon with this neovim setup.

Using all his hotkeys

ThePrimeagen has a video detailing an older version of his setup. While the setup is outdated due to unmaintained nature of packer package manager, the general packages used and remaps that Prime has are relevant. He has added and changed some aspects but the core parts seem to still be relevant, unless I missed something.

Changes you may consider making

When it comes to his harpoon commands, you will want to edit lines 14-17 of ~/.config/nvim/lua/theprimeagen/lazy/local.lua since the right side of his homerow remapping replaces hjkl with htns. This is because Prime uses Dvorak instead of the typical QWERTY setup that most people use. If you use a standard QWERTY board change lines 14-17 from

            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)

to

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

From there you should be all set to use the configuration. Play around with neovim and the setup and dig into the configuration. Please let me know if you run into any trouble running his setup.

Alternative process for starting to use Neovim

Since you said you are new to neovim, I would highly recommend watching Prime's opinion about how one should get started with the vim in general. He advocates starting with vim motions within your current editor (like VSCode, etc) and advocates for kickstart.nvim if you're new to the process of customizing your neovim editor.

jamescarr commented 3 months ago

My recommendation is to just delete the ~/personal/harpoon reference and use the following in packer.lua:

  use({
      "ThePrimeagen/harpoon",
      branch = "harpoon2"
  })
srijan-raghavula commented 2 months ago

It actually worked. So simple.

jakobheine commented 2 months ago

Hi.

You can also rename the local.lua file to harpoon.lua (optional, but good style) and then exchange "dir" with the current lazy.nvim installation guidelines from the repo here: https://github.com/ThePrimeagen/harpoon/tree/harpoon2?tab=readme-ov-file#-installation

final code:

-- ~/.config/nvim/lua/jakobheine/lazy/harpoon.lua
return {
        "ThePrimeagen/harpoon",
        branch = "harpoon2",
        dependencies = { "nvim-lua/plenary.nvim" },
        config = function()
            local harpoon = require("harpoon")

            harpoon:setup()

            vim.keymap.set("n", "<leader>a", function() harpoon:list():add() end)
            vim.keymap.set("n", "<C-e>", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end)

            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)
            vim.keymap.set("n", "<leader><C-h>", function() harpoon:list():replace_at(1) end)
            vim.keymap.set("n", "<leader><C-t>", function() harpoon:list():replace_at(2) end)
            vim.keymap.set("n", "<leader><C-n>", function() harpoon:list():replace_at(3) end)
            vim.keymap.set("n", "<leader><C-s>", function() harpoon:list():replace_at(4) end)
        end
}