begin rebuild of config to separate files
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
return {
|
||||
'ThePrimeagen/harpoon',
|
||||
branch = 'harpoon2',
|
||||
dependencies = { 'nvim-lua/plenary.nvim', 'nvim-telescope/telescope.nvim' },
|
||||
config = function()
|
||||
local harpoon = require 'harpoon'
|
||||
harpoon:setup { settings = { save_on_toggle = true, sync_on_ui_close = true } }
|
||||
|
||||
-- Harpoon list in a Telescope picker, <C-d> removes the selected mark.
|
||||
local conf = require('telescope.config').values
|
||||
local function toggle_telescope(harpoon_files)
|
||||
local file_paths = {}
|
||||
local index_map = {}
|
||||
for i = 1, harpoon_files:length() do
|
||||
local item = harpoon_files:get(i)
|
||||
if item then
|
||||
table.insert(file_paths, item.value)
|
||||
table.insert(index_map, i)
|
||||
end
|
||||
end
|
||||
|
||||
require('telescope.pickers')
|
||||
.new({}, {
|
||||
prompt_title = 'Harpoon',
|
||||
finder = require('telescope.finders').new_table { results = file_paths },
|
||||
previewer = conf.file_previewer {},
|
||||
sorter = conf.generic_sorter {},
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
local actions = require 'telescope.actions'
|
||||
local action_state = require 'telescope.actions.state'
|
||||
local function delete_mark()
|
||||
local selection = action_state.get_selected_entry()
|
||||
harpoon:list():remove_at(index_map[selection.index])
|
||||
actions.close(prompt_bufnr)
|
||||
toggle_telescope(harpoon:list())
|
||||
end
|
||||
map('i', '<C-d>', delete_mark)
|
||||
map('n', '<C-d>', delete_mark)
|
||||
return true
|
||||
end,
|
||||
})
|
||||
:find()
|
||||
end
|
||||
|
||||
local map = vim.keymap.set
|
||||
map('n', '<leader>a', function()
|
||||
harpoon:list():add()
|
||||
end, { desc = 'Harpoon: [A]dd file' })
|
||||
map('n', '<leader>A', function()
|
||||
harpoon:list():remove()
|
||||
end, { desc = 'Harpoon: remove current file' })
|
||||
map('n', '<C-e>', function()
|
||||
toggle_telescope(harpoon:list())
|
||||
end, { desc = 'Harpoon: quick menu' })
|
||||
|
||||
-- <leader>1..4 instead of Prime's <C-h/t/n/s>: those collide with window navigation and
|
||||
-- with <C-t> (jump back after gd) unless you are on a Dvorak home row.
|
||||
for i = 1, 4 do
|
||||
map('n', '<leader>' .. i, function()
|
||||
harpoon:list():select(i)
|
||||
end, { desc = 'Harpoon: file ' .. i })
|
||||
end
|
||||
|
||||
-- <C-S-p>/<C-S-n> never worked: terminals can't tell Ctrl+Shift+p from Ctrl+p.
|
||||
map('n', '[h', function()
|
||||
harpoon:list():prev()
|
||||
end, { desc = 'Harpoon: previous mark' })
|
||||
map('n', ']h', function()
|
||||
harpoon:list():next()
|
||||
end, { desc = 'Harpoon: next mark' })
|
||||
end,
|
||||
}
|
||||
Reference in New Issue
Block a user