Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a command shortcut for NERDTree in Vim editor

I'd like to create an abbreviation for NERDTree on the command-line. I find it annoying have to write :NERDTree every time I want to enable it. So I'd like to type :nr or something like that. Is that possible?

like image 413
Jesse Avatar asked Jun 24 '11 12:06

Jesse


People also ask

How do I switch between Vim and NERDTree?

I normally switch screen in vim using ctrl+h or ctrl+l to switch between NerdTree and vim main window. Vim8 got :term command to bring up terminal which is great!

How do you create a file in NERDTree?

First, bring up NERDTree and navigate to the directory where you want to create the new file. Press m to bring up the NERDTree Filesystem Menu. This menu allows you to create, rename, and delete files and directories. Type a to add a child node and then simply enter the filename.


2 Answers

In my .vimrc I have:

let mapleader = "," nmap <leader>ne :NERDTree<cr> 

So when I need NERDTree I just write ,ne in normal mode.

like image 200
jamapag Avatar answered Sep 19 '22 01:09

jamapag


I find this works very nicely, better than any other suggestions I've tried:

map <silent> <C-n> :NERDTreeFocus<CR> 

You just hit control-n to go back to the hierarchy. Selecting a file name in the hierarchy will switch you, of course, to that file.

  1. It works in both normal and insert mode
  2. It doesn't close the hierarchy as the accepted answer does (using the :NERDTree command starts you from scratch, closing the hierarchy, while using :NERDTreeFocus simply moves the focus, which I think is what you want)
like image 45
iconoclast Avatar answered Sep 17 '22 01:09

iconoclast