doc: tidy quick start, enhance on_attach
This commit is contained in:
parent
5cc18d4f2f
commit
e99616bebe
@ -1,6 +1,6 @@
|
|||||||
*nvim-tree.lua* A File Explorer For Neovim Written In Lua
|
*nvim-tree.lua* A File Explorer For Neovim Written In Lua
|
||||||
|
|
||||||
Author: Yazdani Kiyan <yazdani.kiyan@protonmail.com>
|
Author: Yazdani Kiyan
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
CONTENTS *nvim-tree*
|
CONTENTS *nvim-tree*
|
||||||
@ -73,39 +73,30 @@ Requirements
|
|||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
2. QUICK START *nvim-tree-quickstart*
|
2. QUICK START *nvim-tree-quickstart*
|
||||||
|
>
|
||||||
|
-- disable netrw at the very start of your init.lua (strongly advised)
|
||||||
|
vim.g.loaded_netrw = 1
|
||||||
|
vim.g.loaded_netrwPlugin = 1
|
||||||
|
|
||||||
Setup should be run in a lua file or in a |lua-heredoc| if using in a vim file.
|
-- set termguicolors to enable highlight groups
|
||||||
|
vim.opt.termguicolors = true
|
||||||
|
|
||||||
-- examples for your init.lua
|
-- empty setup using defaults
|
||||||
|
require("nvim-tree").setup()
|
||||||
|
|
||||||
-- disable netrw at the very start of your init.lua (strongly advised)
|
-- OR setup with some options
|
||||||
vim.g.loaded_netrw = 1
|
require("nvim-tree").setup({
|
||||||
vim.g.loaded_netrwPlugin = 1
|
sort_by = "case_sensitive",
|
||||||
|
view = {
|
||||||
-- set termguicolors to enable highlight groups
|
width = 30,
|
||||||
vim.opt.termguicolors = true
|
},
|
||||||
|
renderer = {
|
||||||
-- empty setup using defaults
|
group_empty = true,
|
||||||
require("nvim-tree").setup()
|
},
|
||||||
|
filters = {
|
||||||
-- OR setup with some options
|
dotfiles = true,
|
||||||
require("nvim-tree").setup({
|
},
|
||||||
sort_by = "case_sensitive",
|
})
|
||||||
view = {
|
|
||||||
width = 30,
|
|
||||||
mappings = {
|
|
||||||
list = {
|
|
||||||
{ key = "u", action = "dir_up" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
renderer = {
|
|
||||||
group_empty = true,
|
|
||||||
},
|
|
||||||
filters = {
|
|
||||||
dotfiles = true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
<
|
<
|
||||||
==============================================================================
|
==============================================================================
|
||||||
3. COMMANDS *nvim-tree-commands*
|
3. COMMANDS *nvim-tree-commands*
|
||||||
@ -1729,28 +1720,26 @@ Active mappings may be viewed via HELP, default `g?`. The mapping's description
|
|||||||
is used when displaying HELP.
|
is used when displaying HELP.
|
||||||
|
|
||||||
The `on_attach` function is passed the `bufnr` of nvim-tree. Use
|
The `on_attach` function is passed the `bufnr` of nvim-tree. Use
|
||||||
|vim.keymap.set()| or |nvim_set_keymap()| to define mappings as usual. e.g.
|
|vim.keymap.set()| or |nvim_set_keymap()| to define mappings as usual. e.g. >
|
||||||
>
|
|
||||||
local M = {}
|
|
||||||
|
|
||||||
local api = require("nvim-tree.api")
|
local function my_on_attach(bufnr)
|
||||||
|
local api = require('nvim-tree.api')
|
||||||
|
|
||||||
function M.on_attach(bufnr)
|
local function opts(desc)
|
||||||
-- put some default mappings here
|
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
|
||||||
vim.keymap.set('n', 'h', api.tree.toggle_help, { desc = 'Help', buffer = bufnr, noremap = true, silent = true, nowait = true })
|
|
||||||
vim.keymap.set('n', '?', api.tree.toggle_help, { desc = 'Help', buffer = bufnr, noremap = true, silent = true, nowait = true })
|
|
||||||
vim.keymap.set('n', 'p', M.print_node_path, { desc = 'Print', buffer = bufnr, noremap = true, silent = true, nowait = true })
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.print_node_path()
|
-- put some default mappings here
|
||||||
local node = api.tree.get_node_under_cursor()
|
|
||||||
print(node.absolute_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
require("nvim-tree").setup({
|
-- user mappings
|
||||||
on_attach = M.on_attach,
|
vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help'))
|
||||||
--
|
end
|
||||||
})
|
|
||||||
|
require("nvim-tree").setup({
|
||||||
|
---
|
||||||
|
on_attach = my_on_attach,
|
||||||
|
---
|
||||||
|
})
|
||||||
<
|
<
|
||||||
Mouse support is defined in |KeyBindings|
|
Mouse support is defined in |KeyBindings|
|
||||||
|
|
||||||
@ -1758,6 +1747,17 @@ Single left mouse mappings can be achieved via `<LeftRelease>`.
|
|||||||
|
|
||||||
Single right / middle mouse mappings will require changes to |mousemodel| or |mouse|.
|
Single right / middle mouse mappings will require changes to |mousemodel| or |mouse|.
|
||||||
|
|
||||||
|
You may execute your own functions as well as |nvim-tree-api| functions e.g. >
|
||||||
|
|
||||||
|
local function print_node_path()
|
||||||
|
local api = require('nvim-tree.api')
|
||||||
|
local node = api.tree.get_node_under_cursor()
|
||||||
|
print(node.absolute_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- on_attach
|
||||||
|
vim.keymap.set('n', '<C-P>', print_node_path, opts('Print Path'))
|
||||||
|
<
|
||||||
==============================================================================
|
==============================================================================
|
||||||
6.1 DEFAULT MAPPINGS *nvim-tree-mappings-default*
|
6.1 DEFAULT MAPPINGS *nvim-tree-mappings-default*
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user