Skip to content

Commit

Permalink
nvim - migrate to on_attach for nvim-tree
Browse files Browse the repository at this point in the history
instead of the legacy key mapping way
  • Loading branch information
ryuheechul committed Mar 29, 2023
1 parent 9634364 commit 9f41d39
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions nvim/lua/plugins/system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,6 @@ return {
opts = {
view = {
side = 'right',
mappings = {
custom_only = false,
-- override default mappings
list = {
{ key = { 'o', '<2-LeftMouse>', 'l', 'e' }, action = 'edit' },
{ key = { '-', 'h' }, action = 'dir_up' },
{ key = { '<Tab>' }, cb = ':wincmd w<CR>' },
{ key = { 'q' }, cb = ':q<CR>' },
},
},
},
-- auto_open = true,
-- not available any more
Expand All @@ -102,6 +92,28 @@ return {
disable_netrw = false,
hijack_netrw = false,
open_on_setup = false,
on_attach = function(bufnr)
local api = require 'nvim-tree.api'

local function opts(desc)
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end

-- use default mappings
api.config.mappings.default_on_attach(bufnr)

-- open file in buffer
vim.tbl_map(function(key)
vim.keymap.set('n', key, api.node.open.edit, { buffer = bufnr })
end, { 'o', '<2-LeftMouse>', 'l', 'e' })

-- as well as `-`
vim.keymap.set('n', 'h', api.tree.change_root_to_parent, opts 'Up')
-- to be able to "toggle" the behavior of `change_root_to_parent`
vim.keymap.set('n', '=', api.tree.change_root_to_node, opts 'Change Root')
-- cycle windows
vim.keymap.set('n', '<Tab>', '<Cmd>wincmd w<CR>', { buffer = bufnr })
end,
},
}, -- enhanced filetree replacing netrw
{ -- https://github.com/fregante/GhostText
Expand Down

0 comments on commit 9f41d39

Please sign in to comment.