nvim: make nvim-tree on_attach keymaps local to the tree buffer
This commit is contained in:
parent
077ba38381
commit
9326034ef9
1 changed files with 14 additions and 14 deletions
|
@ -1,23 +1,23 @@
|
||||||
local nt, callback
|
local ok, nt = pcall(require, 'nvim-tree')
|
||||||
|
|
||||||
local ok, _ = pcall(function()
|
|
||||||
nt = require 'nvim-tree'
|
|
||||||
api = require 'nvim-tree.api'
|
|
||||||
end)
|
|
||||||
|
|
||||||
if not ok then return end
|
if not ok then return end
|
||||||
|
|
||||||
|
local on_attach = function(bufnr)
|
||||||
|
local api = require 'nvim-tree.api'
|
||||||
|
local opts = function(desc)
|
||||||
|
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, silent = true }
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.keymap.set('n', 'l', api.node.open.edit, opts('open'))
|
||||||
|
vim.keymap.set('n', '<CR>', api.node.open.edit, opts('open'))
|
||||||
|
vim.keymap.set('n', 'o', api.node.open.edit, opts('open'))
|
||||||
|
vim.keymap.set('n', 'h', api.node.navigate.parent_close, opts('close directory'))
|
||||||
|
end
|
||||||
|
|
||||||
nt.setup {
|
nt.setup {
|
||||||
disable_netrw = true, -- replace netrw with nvim-tree
|
disable_netrw = true, -- replace netrw with nvim-tree
|
||||||
hijack_cursor = true, -- keep the cursor on begin of the filename
|
hijack_cursor = true, -- keep the cursor on begin of the filename
|
||||||
sync_root_with_cwd = true, -- watch for `DirChanged` and refresh the tree
|
sync_root_with_cwd = true, -- watch for `DirChanged` and refresh the tree
|
||||||
|
on_attach = on_attach,
|
||||||
on_attach = function()
|
|
||||||
for _, lhs in ipairs({'l', '<CR>', 'o'}) do
|
|
||||||
vim.keymap.set('n', lhs, api.node.open.edit)
|
|
||||||
end
|
|
||||||
vim.keymap.set('n', 'h', api.node.navigate.parent_close)
|
|
||||||
end,
|
|
||||||
|
|
||||||
git = {
|
git = {
|
||||||
ignore = false, -- don't hide files from .gitignore
|
ignore = false, -- don't hide files from .gitignore
|
||||||
|
|
Loading…
Add table
Reference in a new issue