前言
最近临近开学,为了方便在课堂上随手写一点作业,我开始对neovim进行配置,尽量让它满足一个类Ide的功能,那么必不可少的就是文件树的功能,那么这里,我就来简单记录一下nvim-tree的配置过程。这里我们使用packer插件管理器,对插件进行安装。
需求
neovim >=0.8.0
nvim-web-devicons is optional and used to display file icons. It requires a patched font. Your terminal emulator must be configured to use that font, usually "Hack Nerd Font"
安装nvim-tree
return require('packer').startup(function()
-- Packer can manage itself
use 'wbthomason/packer.nvim'
-- gruvbox theme
use {
"ellisonleao/gruvbox.nvim",
requires = {"rktjmp/lush.nvim"}
}
-- nvim-tree (这个就是插件)
use {
'kyazdani42/nvim-tree.lua',
requires = 'kyazdani42/nvim-web-devicons'
}
end)
考虑到大家都应该会使用packer了,将上述代码写入plugins.lua即可
在init.lua里写入
-- disable netrw at the very start of your init.lua
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-- set termguicolors to enable highlight groups
vim.opt.termguicolors = true
-- empty setup using defaults
require("nvim-tree").setup()
-- OR setup with some options
require("nvim-tree").setup({
sort_by = "case_sensitive",
view = {
width = 30,
},
renderer = {
group_empty = true,
},
filters = {
dotfiles = true,
},
})
创建 lua/plugin-config/nvim-tree.lua 文件,在里面写入
local function my_on_attach(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
-- default mappings
api.config.mappings.default_on_attach(bufnr)
-- custom mappings
vim.keymap.set('n', '<C-t>', api.tree.change_root_to_parent, opts('Up'))
vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help'))
end
-- pass to setup along with your other options
require("nvim-tree").setup {
---
on_attach = my_on_attach,
---
}
自此,我们就已经安装完成了,只需要在nvim里面输入:TreeToggle即可打开文件树。接下来我们开始配置快捷键
**在/lua/keybindings.lua 写入**
-- nvimTree
map('n', '
这样就可以使用Alt+M来打开,Atl+hjkl来切换了。
标签:--,setup,tree,lua,设置,true,nvim
From: https://www.cnblogs.com/NexusXian/p/17675689.html