2021-11-26 04:27:56 +01:00
|
|
|
<div align="center">
|
|
|
|
|
2023-11-30 19:29:45 +01:00
|
|
|
## ⇁ HARPOON 2
|
|
|
|
This is a deprecated and all future changes will be to the branch `harpoon2`.
|
|
|
|
|
|
|
|
[Harpoon 2](https://github.com/ThePrimeagen/harpoon/tree/harpoon2)
|
|
|
|
|
|
|
|
**STATUS**: Merging into mainline April 20th or June 9th (nice)
|
|
|
|
|
|
|
|
-------------------------------
|
|
|
|
# Legacy Harpoon README
|
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
# Harpoon
|
|
|
|
##### Getting you where you want with the fewest keystrokes.
|
|
|
|
|
|
|
|
[![Lua](https://img.shields.io/badge/Lua-blue.svg?style=for-the-badge&logo=lua)](http://www.lua.org)
|
|
|
|
[![Neovim](https://img.shields.io/badge/Neovim%200.5+-green.svg?style=for-the-badge&logo=neovim)](https://neovim.io)
|
|
|
|
</div>
|
2021-02-19 23:36:09 +01:00
|
|
|
|
2021-03-23 17:36:40 +01:00
|
|
|
![Harpoon](harpoon.png)
|
2022-03-21 19:29:48 +01:00
|
|
|
-- image provided by **Bob Rust**
|
2021-11-26 04:27:56 +01:00
|
|
|
|
|
|
|
## ⇁ WIP
|
|
|
|
This is not fully baked, though used by several people. If you experience any
|
|
|
|
issues, see some improvement you think would be amazing, or just have some
|
|
|
|
feedback for harpoon (or me), make an issue!
|
2021-02-19 05:06:08 +01:00
|
|
|
|
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
## ⇁ The Problems:
|
|
|
|
1. You're working on a codebase. medium, large, tiny, whatever. You find
|
2022-02-10 03:55:47 +01:00
|
|
|
yourself frequenting a small set of files and you are tired of using a fuzzy finder,
|
2021-11-26 04:27:56 +01:00
|
|
|
`:bnext` & `:bprev` are getting too repetitive, alternate file doesn't quite cut it, etc etc.
|
|
|
|
1. You want to execute some project specific commands or have any number of
|
2021-04-14 16:23:46 +02:00
|
|
|
persistent terminals that can be easily navigated to.
|
|
|
|
|
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
## ⇁ The Solutions:
|
|
|
|
1. The ability to specify, or on the fly, mark and create persisting key strokes
|
|
|
|
to go to the files you want.
|
|
|
|
1. Unlimited terminals and navigation.
|
2020-11-06 16:28:18 +01:00
|
|
|
|
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
## ⇁ Installation
|
|
|
|
* neovim 0.5.0+ required
|
|
|
|
* install using your favorite plugin manager (`vim-plug` in this example)
|
2021-04-26 21:47:18 +02:00
|
|
|
```vim
|
|
|
|
Plug 'nvim-lua/plenary.nvim' " don't forget to add this one if you don't have it yet!
|
2020-11-06 16:28:18 +01:00
|
|
|
Plug 'ThePrimeagen/harpoon'
|
|
|
|
```
|
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
## ⇁ Harpooning
|
|
|
|
here we'll explain how to wield the power of the harpoon:
|
2020-11-06 16:28:18 +01:00
|
|
|
|
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
### Marks
|
|
|
|
you mark files you want to revisit later on
|
2021-03-23 16:25:05 +01:00
|
|
|
```lua
|
2021-04-14 16:23:46 +02:00
|
|
|
:lua require("harpoon.mark").add_file()
|
2020-11-06 16:28:18 +01:00
|
|
|
```
|
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
### File Navigation
|
|
|
|
view all project marks with:
|
2021-04-14 16:23:46 +02:00
|
|
|
```lua
|
2021-11-26 04:27:56 +01:00
|
|
|
:lua require("harpoon.ui").toggle_quick_menu()
|
2021-04-14 16:23:46 +02:00
|
|
|
```
|
2021-11-26 04:27:56 +01:00
|
|
|
you can go up and down the list, enter, delete or reorder. `q` and `<ESC>` exit and save the menu
|
2021-04-14 16:23:46 +02:00
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
you also can switch to any mark without bringing up the menu, use the below with the desired mark index
|
2021-04-14 16:23:46 +02:00
|
|
|
```lua
|
2021-11-26 04:27:56 +01:00
|
|
|
:lua require("harpoon.ui").nav_file(3) -- navigates to file 3
|
2021-04-14 16:23:46 +02:00
|
|
|
```
|
2021-12-02 02:02:00 +01:00
|
|
|
you can also cycle the list in both directions
|
|
|
|
```lua
|
|
|
|
:lua require("harpoon.ui").nav_next() -- navigates to next mark
|
|
|
|
:lua require("harpoon.ui").nav_prev() -- navigates to previous mark
|
|
|
|
```
|
2023-11-30 19:29:45 +01:00
|
|
|
from the quickmenu, open a file in:
|
2022-11-24 09:58:56 +01:00
|
|
|
a vertical split with control+v,
|
2023-11-30 19:29:45 +01:00
|
|
|
a horizontal split with control+x,
|
2022-11-24 09:58:56 +01:00
|
|
|
a new tab with control+t
|
2021-04-14 16:23:46 +02:00
|
|
|
|
|
|
|
### Terminal Navigation
|
2021-11-26 04:27:56 +01:00
|
|
|
this works like file navigation except that if there is no terminal at the specified index
|
|
|
|
a new terminal is created.
|
2021-04-14 16:23:46 +02:00
|
|
|
```lua
|
2021-11-26 04:27:56 +01:00
|
|
|
lua require("harpoon.term").gotoTerminal(1) -- navigates to term 1
|
2021-04-14 16:23:46 +02:00
|
|
|
```
|
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
### Commands to Terminals
|
|
|
|
commands can be sent to any terminal
|
2021-04-14 16:23:46 +02:00
|
|
|
```lua
|
2021-11-26 14:30:45 +01:00
|
|
|
lua require("harpoon.term").sendCommand(1, "ls -La") -- sends ls -La to tmux window 1
|
2021-04-14 16:23:46 +02:00
|
|
|
```
|
2021-11-26 04:27:56 +01:00
|
|
|
further more commands can be stored for later quick
|
2021-10-19 09:31:07 +02:00
|
|
|
```lua
|
2021-11-26 04:27:56 +01:00
|
|
|
lua require('harpoon.cmd-ui').toggle_quick_menu() -- shows the commands menu
|
|
|
|
lua require("harpoon.term").sendCommand(1, 1) -- sends command 1 to term 1
|
2021-10-19 09:31:07 +02:00
|
|
|
```
|
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
### Tmux Support
|
|
|
|
tmux is supported out of the box and can be used as a drop-in replacement to normal terminals
|
|
|
|
by simply switching `'term' with 'tmux'` like so
|
2021-11-23 21:02:19 +01:00
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
```lua
|
|
|
|
lua require("harpoon.tmux").gotoTerminal(1) -- goes to the first tmux window
|
2021-11-26 14:30:45 +01:00
|
|
|
lua require("harpoon.tmux").sendCommand(1, "ls -La") -- sends ls -La to tmux window 1
|
2021-11-26 04:27:56 +01:00
|
|
|
lua require("harpoon.tmux").sendCommand(1, 1) -- sends command 1 to tmux window 1
|
|
|
|
```
|
2021-11-23 21:02:19 +01:00
|
|
|
|
2022-01-23 02:27:11 +01:00
|
|
|
`sendCommand` and `goToTerminal` also accept any valid [tmux pane identifier](https://man7.org/linux/man-pages/man1/tmux.1.html#COMMANDS).
|
|
|
|
```lua
|
|
|
|
lua require("harpoon.tmux").gotoTerminal("{down-of}") -- focus the pane directly below
|
|
|
|
lua require("harpoon.tmux").sendCommand("%3", "ls") -- send a command to the pane with id '%3'
|
|
|
|
```
|
|
|
|
|
2022-03-31 17:19:26 +02:00
|
|
|
Once you switch to a tmux window you can always switch back to neovim, this is a
|
|
|
|
little bash script that will switch to the window which is running neovim.
|
|
|
|
|
|
|
|
In your `tmux.conf` (or anywhere you have keybinds), add this
|
|
|
|
```bash
|
|
|
|
bind-key -r G run-shell "path-to-harpoon/harpoon/scripts/tmux/switch-back-to-nvim"
|
|
|
|
```
|
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
### Telescope Support
|
|
|
|
1st register harpoon as a telescope extension
|
2021-11-23 21:02:19 +01:00
|
|
|
```lua
|
2021-11-26 04:27:56 +01:00
|
|
|
require("telescope").load_extension('harpoon')
|
|
|
|
```
|
|
|
|
currently only marks are supported in telescope
|
|
|
|
```
|
|
|
|
:Telescope harpoon marks
|
|
|
|
```
|
2021-11-23 21:02:19 +01:00
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
## ⇁ Configuration
|
|
|
|
if configuring harpoon is desired it must be done through harpoons setup function
|
|
|
|
```lua
|
|
|
|
require("harpoon").setup({ ... })
|
2021-11-23 21:02:19 +01:00
|
|
|
```
|
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
### Global Settings
|
|
|
|
here are all the available global settings with their default values
|
|
|
|
```lua
|
|
|
|
global_settings = {
|
|
|
|
-- sets the marks upon calling `toggle` on the ui, instead of require `:w`.
|
|
|
|
save_on_toggle = false,
|
2021-04-14 16:23:46 +02:00
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
-- saves the harpoon file upon every change. disabling is unrecommended.
|
|
|
|
save_on_change = true,
|
2021-04-14 16:23:46 +02:00
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
-- sets harpoon to run the command immediately as it's passed to the terminal when calling `sendCommand`.
|
|
|
|
enter_on_sendcmd = false,
|
2021-04-14 16:23:46 +02:00
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
-- closes any tmux windows harpoon that harpoon creates when you close Neovim.
|
|
|
|
tmux_autoclose_windows = false,
|
2021-04-14 16:23:46 +02:00
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
-- filetypes that you want to prevent from adding to the harpoon list menu.
|
2022-02-10 03:55:47 +01:00
|
|
|
excluded_filetypes = { "harpoon" },
|
|
|
|
|
|
|
|
-- set marks specific to each git branch inside git repository
|
|
|
|
mark_branch = false,
|
2023-05-10 15:01:54 +02:00
|
|
|
|
|
|
|
-- enable tabline with harpoon marks
|
|
|
|
tabline = false,
|
|
|
|
tabline_prefix = " ",
|
|
|
|
tabline_suffix = " ",
|
2021-11-26 04:27:56 +01:00
|
|
|
}
|
2021-04-14 16:23:46 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
### Preconfigured Terminal Commands
|
|
|
|
to preconfigure terminal commands for later use
|
2021-04-14 16:23:46 +02:00
|
|
|
```lua
|
2021-11-26 14:30:45 +01:00
|
|
|
projects = {
|
|
|
|
-- Yes $HOME works
|
|
|
|
["$HOME/personal/vim-with-me/server"] = {
|
|
|
|
term = {
|
|
|
|
cmds = {
|
|
|
|
"./env && npx ts-node src/index.ts"
|
2021-04-14 16:23:46 +02:00
|
|
|
}
|
2021-11-26 04:27:56 +01:00
|
|
|
}
|
|
|
|
}
|
2021-11-26 14:30:45 +01:00
|
|
|
}
|
2021-04-14 16:23:46 +02:00
|
|
|
```
|
|
|
|
|
2021-11-26 04:27:56 +01:00
|
|
|
## ⇁ Logging
|
|
|
|
- logs are written to `harpoon.log` within the nvim cache path (`:echo stdpath("cache")`)
|
|
|
|
- available log levels are `trace`, `debug`, `info`, `warn`, `error`, or `fatal`. `warn` is default
|
|
|
|
- log level can be set with `vim.g.harpoon_log_level` (must be **before** `setup()`)
|
|
|
|
- launching nvim with `HARPOON_LOG=debug nvim` takes precedence over `vim.g.harpoon_log_level`.
|
|
|
|
- invalid values default back to `warn`.
|
|
|
|
|
|
|
|
## ⇁ Others
|
|
|
|
#### How do Harpoon marks differ from vim global marks
|
2022-02-06 13:45:29 +01:00
|
|
|
they serve a similar purpose however harpoon marks differ in a few key ways:
|
2021-11-26 04:27:56 +01:00
|
|
|
1. They auto update their position within the file
|
|
|
|
1. They are saved _per project_.
|
|
|
|
1. They can be hand edited vs replaced (swapping is easier)
|
|
|
|
|
|
|
|
#### The Motivation behind Harpoon terminals
|
|
|
|
1. I want to use the terminal since I can gF and <c-w>gF to any errors arising
|
|
|
|
from execution that are within the terminal that are not appropriate for
|
|
|
|
something like dispatch. (not just running tests but perhaps a server that runs
|
|
|
|
for X amount of time before crashing).
|
|
|
|
1. I want the terminal to be persistent and I can return to one of many terminals
|
|
|
|
with some finger wizardry and reparse any of the execution information that was
|
|
|
|
not necessarily error related.
|
|
|
|
1. I would like to have commands that can be tied to terminals and sent them
|
|
|
|
without much thinking. Some sort of middle ground between vim-test and just
|
|
|
|
typing them into a terminal (configuring netflix's television project isn't
|
|
|
|
quite building and there are tons of ways to configure).
|
2022-02-14 20:42:07 +01:00
|
|
|
|
|
|
|
#### Use a dynamic width for the Harpoon popup menu
|
|
|
|
Sometimes the default width of `60` is not wide enough.
|
|
|
|
The following example demonstrates how to configure a custom width by setting
|
|
|
|
the menu's width relative to the current window's width.
|
|
|
|
|
|
|
|
```lua
|
|
|
|
require("harpoon").setup({
|
|
|
|
menu = {
|
|
|
|
width = vim.api.nvim_win_get_width(0) - 4,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
2022-03-21 19:49:01 +01:00
|
|
|
|
2023-05-10 15:01:54 +02:00
|
|
|
|
|
|
|
#### Tabline
|
|
|
|
|
|
|
|
By default, the tabline will use the default theme of your theme. You can customize by editing the following highlights:
|
|
|
|
|
|
|
|
* HarpoonInactive
|
|
|
|
* HarpoonActive
|
|
|
|
* HarpoonNumberActive
|
|
|
|
* HarpoonNumberInactive
|
|
|
|
|
|
|
|
Example to make it cleaner:
|
|
|
|
|
|
|
|
```lua
|
|
|
|
vim.cmd('highlight! HarpoonInactive guibg=NONE guifg=#63698c')
|
|
|
|
vim.cmd('highlight! HarpoonActive guibg=NONE guifg=white')
|
|
|
|
vim.cmd('highlight! HarpoonNumberActive guibg=NONE guifg=#7aa2f7')
|
|
|
|
vim.cmd('highlight! HarpoonNumberInactive guibg=NONE guifg=#7aa2f7')
|
|
|
|
vim.cmd('highlight! TabLineFill guibg=NONE guifg=white')
|
|
|
|
```
|
|
|
|
|
2023-11-30 19:29:45 +01:00
|
|
|
Result:
|
|
|
|
![tabline](https://i.imgur.com/8i8mKJD.png)
|
2023-05-10 15:01:54 +02:00
|
|
|
|
2022-03-21 19:49:01 +01:00
|
|
|
## ⇁ Social
|
2023-12-20 05:20:35 +01:00
|
|
|
For questions about Harpoon, there's a #harpoon channel on [the Primeagen's Discord](https://discord.gg/theprimeagen) server.
|
2022-03-21 19:49:01 +01:00
|
|
|
* [Discord](https://discord.gg/theprimeagen)
|
|
|
|
* [Twitch](https://www.twitch.tv/theprimeagen)
|
|
|
|
* [Twitter](https://twitter.com/ThePrimeagen)
|