Harpoon’s marking system provides a fast, index-based approach to navigate between your most important files. Unlike Vim’s global marks, Harpoon marks are project-specific and automatically track cursor positions.
-- Get the current file's mark indexlocal current_idx = mark.get_current_index()if current_idx then print("This file is mark #" .. current_idx)end-- Get mark by indexlocal mark_data = mark.get_marked_file(1)if mark_data then print(mark_data.filename) -- File path print(mark_data.row) -- Row number print(mark_data.col) -- Column numberend-- Get just the filenamelocal filename = mark.get_marked_file_name(3)-- Get total number of markslocal count = mark.get_length()
Harpoon automatically updates cursor positions when you leave a marked buffer:
-- From mark.lua:255-282function M.store_offset() local marks = harpoon.get_mark_config().marks local buf_name = get_buf_name() local idx = M.get_index_of(buf_name, marks) if not M.valid_index(idx, marks) then return end local cursor_pos = vim.api.nvim_win_get_cursor(0) marks[idx].row = cursor_pos[1] marks[idx].col = cursor_pos[2]end
This happens automatically via autocmd when you:
Leave a buffer (BufLeave)
Exit Vim (VimLeave)
Enable save_on_change in your configuration to automatically persist marks to disk whenever they change.