“This is the 12th day of my participation in the Gwen Challenge in November. See details of the event: The Last Gwen Challenge 2021”.

preface

  • A lot of people don’t like using Linux commands because Vim doesn’t jump around as easily as development tools. Each time vim is opened, you need to move to the specified place to modify, and then you need to manually command the save yourself.
  • The main reason is that vim does not quickly understand the project directory structure. Today we introduce NERDTree, a plugin that solves the problem of our project structure

The installation

  • wget http://www.vim.org/scripts/download_script.php?src_id=17123 -O nerdtree.zip
  • First we download, then unzip and copy the files
unzip nerdtree.zip  
mkdir -p ~/.vim/{plugin,doc}  
cp plugin/NERD_tree.vim ~/.vim/plugin/  
cp doc/NERD_tree.txt ~/.vim/doc/
Copy the code

validation

  • Once installed, we can type vim anywhere

  • Then we input in VIM mode:NERDTreeAnd you can see our tree structure

  • In the properties structure we can expand folders and collapse folders with the mouse

  • NERDTree has been installed. Let’s see how it works

Set Vim to automatically open NERDTree

" NERDTree config
#Set shortcut keys
map <F4> :NERDTreeMirror<CR>
map <F2> :NERDTreeToggle<CR>
#It only needs to be closed once, and it seems to have no effect during my test
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") &&b:NERDTreeType == "primary") | q | endif
#Vim opens automatic NERDTree
autocmd vimenter * NERDTree
Copy the code

The cursor operation

CTRL + W + H cursor Focus on the left tree directory CTRL + W + L cursor focus on the right file display window CTRL + W + W cursor automatically switch between the left and right Windows #!! CTRL + W + R moves the layout of the current windowCopy the code
O Open a file, directory, or bookmark in an existing window and jump to that window go Open a file, directory, or bookmark in an existing window but do not jump to that window t Open the selected file/bookmark in a new Tab and jump to a new Tab T Open the selected file/bookmark in a new Tab, But instead of going to a new Tab I split a new window opens up the selected file and goes to that window gi split a new window opens up the selected file, but instead of going to s vsplit a new window opens up the selected file and goes to gs vsplit a new window opens up the selected file, But do not jump to the window! Run the current file O recursively open all directories under the selected node x recursively close all directories under the selected node x recursively close all directories under the selected node e Edit the current dif double-click NERDTree-o key pair file NERDTree-i NERDTree-e D: delete bookmark P, jump to root, P, jump to parent, K, jump to first node of the same level in current directory, J, jump to last node of the same level in current directory, K, jump to last node of the same level in current directory, J, jump to last node of the same level in current directory, C Directory will be selected or select the file's parent directory for the root node u will be the root node of the parent directory to the root directory, and folded into the original root node u will be the root node of the parent directory to the root directory, but keep an original root node r recursive recursive refresh to refresh the selected directory r m root nodes according to the file system menu #!!!!!! CD Set CWD to the selected directory. I Toggle whether to display hidden files. F Toggle whether to use file filters. Toggles whether Quick Help is displayedCopy the code