nvim: Added harpoon + autocmd

Signed-off-by: Sagi Dayan <sagidayan@gmail.com>
This commit is contained in:
Sagi Dayan 2024-04-04 17:00:32 +03:00
parent c3784e0a65
commit 90dfbaf600
Signed by: sagi
GPG key ID: FAB96BFC63B46458
5 changed files with 63 additions and 1 deletions

View file

@ -0,0 +1,13 @@
-- update tree if open on file enter
local api = vim.api
api.nvim_create_autocmd('BufEnter', {
callback = function()
local tree_ok, tree_api = pcall(require, "nvim-tree.api")
if tree_ok and tree_api.tree.is_visible() then
-- local win_number = api.nvim_get_current_win()
tree_api.tree.find_file()
end
end
})

View file

@ -10,6 +10,7 @@ require("user.treesitter")
require("user.keymaps")
require("user.lualine")
require("user.colors")
require("user.autocmd")
-- Make sure plugins are installed
--vim.cmd(":PackerClean")

View file

@ -78,3 +78,13 @@ local notify_ok, notify = pcall(require, "notify")
if notify_ok then
vim.notify = notify
end
local harpoon_ok, harpoon = pcall(require, "harpoon")
if harpoon_ok then
harpoon.setup({
settings = {
save_on_toggle = false,
sync_on_ui_close = true,
}
})
end

View file

@ -32,6 +32,39 @@ if telescope_status_ok then
nnoremap("<C-f>", telescope.current_buffer_fuzzy_find)
end
-- Harpoon
local harpoon_ok, harpoon = pcall(require, "harpoon")
if harpoon_ok then
nnoremap("<leader>hx", function() harpoon:list():add() end)
nnoremap("<leader>hn", function() harpoon:list():next() end)
nnoremap("<leader>hp", function() harpoon:list():prev() end)
if telescope_status_ok then
-- basic telescope configuration
local conf = require("telescope.config").values
local function toggle_telescope(harpoon_files)
local file_paths = {}
for _, item in ipairs(harpoon_files.items) do
table.insert(file_paths, item.value)
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({}),
}):find()
end
nnoremap("<leader>hh", function() toggle_telescope(harpoon:list()) end,
{ desc = "Open harpoon window" })
else
nnoremap("<leader>hh", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end)
end
end
-- Copy to system clipboard
vnoremap('<leader>y', '"+y')
nnoremap('<leader>Y', '"+yg_')

View file

@ -68,11 +68,16 @@ return require("packer").startup(function(use)
config = function() require("nvim-autopairs").setup {} end
}
-- Telescope (fzf)
-- Telescope (fzf) and Harpoon
use {
'nvim-telescope/telescope.nvim',
requires = { { 'nvim-lua/plenary.nvim' } }
}
use {
"ThePrimeagen/harpoon",
branch = "harpoon2",
requires = { { "nvim-lua/plenary.nvim" } }
}
if is_workstation then
use {