Vim 插件(一) 文件树

文章目录

GitHub仓库地址: https://github.com/minhanghuang/nvim

Vim 插件 文件树

https://github.com/kyazdani42/nvim-tree.lua

vim-plug

Plug 'kyazdani42/nvim-tree.lua'

添加.lua配置

midir -p ~/.config/nvim/lua/plugin
touch nvim-tree.lua

nvim-tree.lua添加一下内容

-- following options are the default
local tree_cb = require'nvim-tree.config'.nvim_tree_callback
require'nvim-tree'.setup {
	-- disables netrw completely
	disable_netrw       = false,
	-- hijack netrw window on startup
	hijack_netrw        = true,
	-- open the tree when running this setup function
	open_on_setup       = true,
	-- will not open on setup if the filetype is in this list
	ignore_ft_on_setup  = {},
	-- closes neovim automatically when the tree is the last **WINDOW** in the view
	auto_close          = true,
	-- opens the tree when changing/opening a new tab if the tree wasn't previously opened
	open_on_tab         = true,
	-- hijacks new directory buffers when they are opened.
	update_to_buf_dir   = {
		-- enable the feature
		enable = true,
		-- allow to open the tree if it was previously closed
		auto_open = true,
	},
	-- hijack the cursor in the tree to put it at the start of the filename
	hijack_cursor       = false,
	-- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually)
	update_cwd          = false,
	-- show lsp diagnostics in the signcolumn
	lsp_diagnostics     = false,
	-- update the focused file on `BufEnter`, un-collapses the folders recursively until it finds the file
	update_focused_file = {
		-- enables the feature
		enable      = false,
		-- update the root directory of the tree to the one of the folder containing the file if the file is not under the current root directory
		-- only relevant when `update_focused_file.enable` is true
		update_cwd  = false,
		-- list of buffer names / filetypes that will not update the cwd if the file isn't found under the current root directory
		-- only relevant when `update_focused_file.update_cwd` is true and `update_focused_file.enable` is true
		ignore_list = {}
	},
	-- configuration options for the system open command (`s` in the tree by default)
	system_open = {
		-- the command to run this, leaving nil should work in most cases
		cmd  = nil,
		-- the command arguments as a list
		args = {}
	},
  git = {
    enable = true,
    -- 显示被git忽略的文件
    ignore = false,
    timeout = 500,
  },
	view = {
		-- width of the window, can be either a number (columns) or a string in `%`, for left or right side placement
		width = 30,
		-- height of the window, can be either a number (columns) or a string in `%`, for top or bottom side placement
		height = 30,
		-- side of the tree, can be one of 'left' | 'right' | 'top' | 'bottom'
		side = 'left',
		-- if true the tree will resize itself after opening a file
		auto_resize = true,
		mappings = {
			-- custom only false will merge the list with the default mappings
			-- if true, it will only use your list to set the mappings
			custom_only = true,
			-- list of mappings to set on the tree manually
			list = {
				{ key = {"<CR>", "o", "<2-LeftMouse>","l"}, cb = tree_cb("edit") },
				{ key = {"<2-RightMouse>", "<C-]>"},    cb = tree_cb("cd") },
				{ key = "<C-v>",                        cb = tree_cb("vsplit") },
				{ key = "<C-x>",                        cb = tree_cb("split") },
				{ key = "<C-t>",                        cb = tree_cb("tabnew") },
				{ key = "<",                            cb = tree_cb("prev_sibling") },
				{ key = ">",                            cb = tree_cb("next_sibling") },
				{ key = {"P"},                            cb = tree_cb("parent_node") },
				--{ key = "<BS>",                         cb = tree_cb("close_node") },
				{ key = "<S-CR>",                       cb = tree_cb("close_node") },
				{ key = "<Tab>",                        cb = tree_cb("preview") },
				{ key = "K",                            cb = tree_cb("first_sibling") },
				{ key = "J",                            cb = tree_cb("last_sibling") },
				{ key = "I",                            cb = tree_cb("toggle_ignored") },
				{ key = {"H","<BS>"},                            cb = tree_cb("toggle_dotfiles") },
				{ key = "R",                            cb = tree_cb("refresh") },
				{ key = "a",                            cb = tree_cb("create") },
				{ key = "d",                            cb = tree_cb("remove") },
				{ key = "r",                            cb = tree_cb("rename") },
				{ key = "<C-r>",                        cb = tree_cb("full_rename") },
				{ key = "x",                            cb = tree_cb("cut") },
				{ key = "c",                            cb = tree_cb("copy") },
				{ key = "p",                            cb = tree_cb("paste") },
				{ key = "y",                            cb = tree_cb("copy_name") },
				{ key = "Y",                            cb = tree_cb("copy_path") },
				{ key = "gy",                           cb = tree_cb("copy_absolute_path") },
				{ key = "[c",                           cb = tree_cb("prev_git_item") },
				{ key = "]c",                           cb = tree_cb("next_git_item") },
				{ key = {"-","h"},                            cb = tree_cb("dir_up") },
				--{ key = "s",                            cb = tree_cb("system_open") },
				--{ key = "s",                            cb = tree_cb("close") },
				{ key = {"q"},                            cb = tree_cb("close") },
				{ key = "g?",                           cb = tree_cb("toggle_help") },
			}


		}
	}
}

添加maps

// init.vim 
lua require("plugin/nvim-tree")
nmap <silent> <Leader>o :NvimTreeToggle<CR>

切换窗口: Ctrl+ww

文件树默认不显示被git忽略的文件,设置显示背git忽略的文件

// nvim-tree.lua
git = {
    enable = true,
    -- 显示被git忽略的文件 
    ignore = false,
    timeout = 500,
  },

在这里插入图片描述

文件icon不显示?

  • 解决:

不显示icon的原因是当前字体没有icon,这里提到的字体是当前终端的字体,不是系统的字体,举个例子:我使用Mac远程登录这台机器,那么字体就是当前Mac的终端字体,需要对Mac终端配置有icon的字体; 如果是在Ubuntu内打开的终端,就需要对Ubuntu的终端配置合适的字体

字体下载链接: https://github.com/ryanoasis/nerd-fonts

我这里使用的是DroidSansMono字体(https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/DroidSansMono/complete),Mac默认的Monaco字体不显示icon

在这里插入图片描述

以下是一个基于Vundle插件管理器的完整vim插件配置样例,包含常用插件和快捷键绑定等: ``` set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " let Vundle manage Vundle, required Plugin 'VundleVim/Vundle.vim' " Add your plugins here Plugin 'scrooloose/nerdtree' " 文件 Plugin 'tpope/vim-fugitive' " Git Plugin 'jiangmiao/auto-pairs' " 自动补全括号 Plugin 'vim-airline/vim-airline' " 状态栏 Plugin 'vim-airline/vim-airline-themes' " 状态栏主题 Plugin 'tpope/vim-surround' " 快捷键快速包围文本 Plugin 'tpope/vim-repeat' " 使 . 命令支持插件操作 Plugin 'tpope/vim-commentary' " 快速注释 Plugin 'preservim/nerdcommenter' " 快速注释 Plugin 'vim-scripts/indentpython.vim' " Python缩进 Plugin 'SirVer/ultisnips' " 代码片段 Plugin 'honza/vim-snippets' " 代码片段 Plugin 'fatih/vim-go' " Golang 工具 " All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required " 定义快捷键 nnoremap <C-n> :NERDTreeToggle<CR> " 打开/关闭文件 nnoremap <leader>gs :Git<CR> " 打开 Git 窗口 nnoremap <leader>gb :Git blame<CR> " Git blame nnoremap <leader>gc :Git commit<CR> " Git commit nnoremap <leader>gd :Gdiff<CR> " Git diff nnoremap <leader>gl :Glog<CR> " Git log nnoremap <leader>gp :Git push<CR> " Git push nnoremap <leader>gs :Gstatus<CR> " Git status nnoremap <leader>gw :Gwrite<CR> " Git write " 设置状态栏主题 let g:airline_theme='molokai' ``` 保存并退出`~/.vimrc`文件,然后打开vim,执行以下命令,安装配置好的插件: ``` :PluginInstall ``` Vundle将自动从GitHub上下载和安装已列出的插件。 至此,你的vim插件全套配置已完成。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值