The method of implementing the directory on the left and the content layout on the right in the vim editor (vim plug-in: display tree directory plug-in NERDTree installation and use)

NERDTree : is a file system explorer for the Vim editor. Using this plugin, users can intuitively navigate complex directory hierarchies, quickly open files for reading or editing, and perform basic file system operations.

It allows easy browsing of files and performing some basic operations like creating or moving files without leaving vim.

Can be integrated with Git: used to show which file has been modified

github address: https://github.com/preservim/nerdtree

The effect is as follows:
insert image description here

1. Installation method

1. The terminal downloads the compressed file

wget http://www.vim.org/scripts/download_script.php?src_id=17123 -O nerdtree.zip

2. Unzip

unzip nerdtree.zip

3. Create .vim/{plugin,doc} in the home directory

mkdir -p ~/.vim/{plugin,doc}

4. Copy two files

cp plugin/NERD_tree.vim ~/.vim/plugin/
cp doc/NERD_tree.txt ~/.vim/doc/

After installation, open vim, enter: NERDTree in vim, you can see the effect of NERDTree.

5. Press F3 to open and close NERDTree

~/.vimrcAdd the following two lines to :

" 设置NerdTree
map <F3> :NERDTreeMirror<CR>
map <F3> :NERDTreeToggle<CR>

If you want to open vim to automatically enter NERDTree, ~/.vimrcadd the following to the file

autocmd VimEnter * NERDTree

2. Commonly used shortcut keys

1. Switch tabs

:tabnew [++opt选项] [+cmd] 文件      建立对指定文件新的tab
:tabc   关闭当前的 tab
:tabo   关闭所有其他的 tab
:tabs   查看所有打开的 tab
:tabp   前一个 tab
:tabn   后一个 tab

2. Switch workbench and directory

ctrl + w + h    光标 focus 左侧树形目录
ctrl + w + l    光标 focus 右侧文件显示窗口
ctrl + w + w    光标自动在左右侧窗口切换
ctrl + w + r    移动当前窗口的布局位置
o       在已有窗口中打开文件、目录或书签,并跳到该窗口
go      在已有窗口 中打开文件、目录或书签,但不跳到该窗口
t       在新 Tab 中打开选中文件/书签,并跳到新 Tab
T       在新 Tab 中打开选中文件/书签,但不跳到新 Tab
i       split 一个新窗口打开选中文件,并跳到该窗口
gi      split 一个新窗口打开选中文件,但不跳到该窗口
s       vsplit 一个新窗口打开选中文件,并跳到该窗口
gs      vsplit 一个新 窗口打开选中文件,但不跳到该窗口
!       执行当前文件
O       递归打开选中 结点下的所有目录
x       合拢选中结点的父目录
X       递归 合拢选中结点下的所有目录
e       Edit the current dif
双击    相当于 NERDTree-o
中键    对文件相当于 NERDTree-i,对目录相当于 NERDTree-e
D       删除当前书签
P       跳到根结点
p       跳到父结点
K       跳到当前目录下同级的第一个结点
J       跳到当前目录下同级的最后一个结点
k       跳到当前目录下同级的前一个结点
j       跳到当前目录下同级的后一个结点
C       将选中目录或选中文件的父目录设为根结点
u       将当前根结点的父目录设为根目录,并变成合拢原根结点
U       将当前根结点的父目录设为根目录,但保持展开原根结点
r       递归刷新选中目录
R       递归刷新根结点
m       显示文件系统菜单
cd      将 CWD 设为选中目录
I       切换是否显示隐藏文件
f       切换是否使用文件过滤器
F       切换是否显示文件
B       切换是否显示书签
q       关闭 NerdTree 窗口
?       切换是否显示 Quick Help

3. In standard mode

gT      前一个 tab
gt      后一个 tab
MacVim 还可以借助快捷键来完成 tab 的关闭、切换
cmd+w   关闭当前的 tab
cmd+{   前一个 tab
cmd+}   后一个 tab
NerdTree 在 .vimrc 中的常用配置

other

If you don't want to use plugins, vim also comes with a file browser:netrw

Official website: https://shapedshed.com/vim-netrw/

Advantage:

  • Vim's own file browser

  • How to use: Explore, :Sexplore, :Vexplore, or :Sex, :Vex

  • Press i to get different views of the file directory

  • Set default view: let g:netrw_liststyle = 3

  • Do not display the banner (explanation text) button I, let g:netrw_banner = 0

  • File opening method let g:netrw_browse_split = 1

  • Implement NERDtree with netrw

Guess you like

Origin blog.csdn.net/cui_yonghua/article/details/131657518