Harpoon Lualine Plugin

September 11, 2024 ยท View on GitHub

Screenshot 2024-03-15 at 12 47 08โ€ฏPM

Add a harpoon indicator to your Neovim Lualine!

Features

Important


Make sure to install harpoon2 , not harpoon on master branch

Installation

  • With lazy.nvim
  {
    "letieu/harpoon-lualine",
    dependencies = {
      {
        "ThePrimeagen/harpoon",
        branch = "harpoon2",
      }
    },
  }
  • With packer.nvim
  use {
    'letieu/harpoon-lualine',
    opt = false,
    requires = {{'ThePrimeagen/harpoon'}}
  }

Usage

Add this to your Lualine setup:

lualine_c = { "harpoon2" },

Custom config

lualine_c = {
  {
    "harpoon2",
    icon = 'โ™ฅ',
    indicators = { "a", "s", "q", "w" },
    active_indicators = { "A", "S", "Q", "W" },
    color_active = { fg = "#00ff00" },
    _separator = " ",
    no_harpoon = "Harpoon not loaded",
  },
}

Use function as indicator

  -- harpoon_entry = {
  --   context = { col = 0, row = 1 },
  --   value = "init.lua"
  -- }
  local function get_harpoon_indicator(harpoon_entry)
    return harpoon_entry.value
  end

  -- lualine setup
  ...
  active_indicators = {
    get_harpoon_indicator,
    get_harpoon_indicator,
    get_harpoon_indicator,
    get_harpoon_indicator,
  },
  ...

How I use harpoon ๐Ÿ’ก

Bind harpoon mark to a, s, q, w and use Ctrl + a, s, q, w to jump to the mark.

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

View current marks with lualine

lualine_c = { 
  '%=', -- make the indicator center
  {
    "harpoon2",
    indicators = { "a", "s", "q", "w" },
    active_indicators = { "A", "S", "Q", "W" },
    _separator = " ",
  }
}

Enjoy!

Note: Customize indicator characters by editing the configuration.

Note: To center the indicator, add a %=. For example: lualine_c = { "%=", "harpoon2"},

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

Taken
Taken

๐Ÿ’ป
Le Tieu
Le Tieu

๐Ÿšง ๐Ÿค”
simachri
simachri

๐Ÿ’ป
Patrick Dewey
Patrick Dewey

๐Ÿ’ป
Owen L.
Owen L.

๐Ÿ’ป
Nguyen Ngoc Minh Tu
Nguyen Ngoc Minh Tu

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!