harpoon icon indicating copy to clipboard operation
harpoon copied to clipboard

'Esc' in normal mode jumps to first harpoon entry

Open db757 opened this issue 6 months ago • 0 comments

Whenever I have at least one item in the harpoon list, hitting Esc in normal mode in any buffer jumps to the buffer that's in the first harpoon entry. If there's no entries in the list then nothing happens (as expected).

Here's my lazy config:

return
{
	'ThePrimeagen/harpoon',
	branch = 'harpoon2',
	dependencies = { 'nvim-lua/plenary.nvim' },
	config = function()
                local harpoon = require('harpoon')
		harpoon:setup({
			settings = {
				save_on_toggle = true,
				sync_on_ui_close = true,
			},
		})

		local nmap = function(key, cmd, desc)
			local opts = { noremap = true, silent = true }
			opts.desc = desc
			vim.keymap.set('n', key, cmd, opts)
		end

		nmap('<leader>a', function() harpoon:list():add() end, 'Harpoon: Add buffer to list')
		nmap('<C-e>', function() harpoon.ui:toggle_quick_menu(harpoon:list()) end, 'Harpoon: Toggle quick menu')
		nmap('<C-]>', function() harpoon:list():next() end, 'Harpoon: Next entry')
		nmap('<C-[>', function() harpoon:list():prev() end, 'Harpoon: Previous entry')

		local group = vim.api.nvim_create_augroup('harpoonGroup', { clear = true })

		-- Save exact cursor position when leaving buffer
		vim.api.nvim_create_autocmd({ 'BufLeave', 'ExitPre' }, {
			pattern = '*',
			group = group,
			callback = function()
				local filename = vim.fn.expand('%:p:.')
				local harpoon_marks = harpoon:list().items
				for _, mark in ipairs(harpoon_marks) do
					if mark.value == filename then
						mark.context.row = vim.fn.line('.')
						mark.context.col = vim.fn.col('.')
						return
					end
				end
			end,
		})

		vim.api.nvim_create_autocmd({ 'Filetype' }, {
			pattern = 'harpoon',
			group = group,
			callback = function()
				vim.opt.cursorline = true
			end
		})

		harpoon:extend({
			UI_CREATE = function(cx)
				vim.keymap.set('n', '<C-v>', function()
					harpoon.ui:select_menu_item({ vsplit = true })
				end, { buffer = cx.bufnr })

				vim.keymap.set('n', '<C-x>', function()
					harpoon.ui:select_menu_item({ split = true })
				end, { buffer = cx.bufnr })
			end,
		})
        end,
}

db757 avatar Jul 27 '24 08:07 db757