vimtricks.wiki Concise Vim tricks, one at a time.

How do I quickly switch between a set of frequently used files with Harpoon?

Answer

:lua require('harpoon.ui').toggle_quick_menu()

Explanation

Harpoon by ThePrimeagen lets you mark a small set of files (typically 4-6) and instantly switch between them with dedicated keybindings. Unlike buffers or marks, Harpoon's file list persists per project and is designed for your most-visited files.

How it works

  • require('harpoon.mark').add_file() — add current file to the Harpoon list
  • require('harpoon.ui').toggle_quick_menu() — show/hide the file list
  • require('harpoon.ui').nav_file(1) — jump to file 1 in the list
  • Files are stored per-project and persist across sessions

Example

" Add keybindings
nnoremap <leader>a :lua require('harpoon.mark').add_file()<CR>
nnoremap <C-e> :lua require('harpoon.ui').toggle_quick_menu()<CR>
nnoremap <C-h> :lua require('harpoon.ui').nav_file(1)<CR>
nnoremap <C-j> :lua require('harpoon.ui').nav_file(2)<CR>
nnoremap <C-k> :lua require('harpoon.ui').nav_file(3)<CR>
nnoremap <C-l> :lua require('harpoon.ui').nav_file(4)<CR>
Harpoon menu:
1: src/main.py
2: src/utils.py
3: tests/test_main.py
4: config.yaml

Press <C-h> → instantly opens src/main.py

Tips

  • Keep your list small (4-6 files) — Harpoon is for your core working set
  • Edit the list in the quick menu — delete lines to remove files, reorder by moving
  • Harpoon 2 uses a new API: require('harpoon'):list():add()
  • Works great with tmux integration for terminal commands too

Next

How do I return to normal mode from absolutely any mode in Vim?