Jesse
Jesse

Reputation: 1469

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?

Upvotes: 46

Views: 37581

Answers (6)

Nefteyugansk
Nefteyugansk

Reputation: 1

.vimrc:

let mapleader = "n" #nerdtree  
nmap <leader> :NERDTreeFocus<cr>
let mapleader = "f" #focus
nmap <leader> :NERDTreeToggle<cr>

.bash_profile:

alias n="vim -c 'NERDTree'"

Upvotes: 0

Alejandro Barrios
Alejandro Barrios

Reputation: 37

add to your rc file (.bashrc / .zshrc) this shortcut

alias nerd="nvim -c \"NERDTree\""

then, reload your bash width

source ~/.zshrc # or ~/.bashrc according your case

and run

nerd

the -c flag allows you to execute a command when starting the terminal

nvim -c "command"

Upvotes: 0

Hulii Borys
Hulii Borys

Reputation: 272

For ex Sublime users:

map <silent> <C-k>b :NERDTreeToggle<CR>

Upvotes: 6

iconoclast
iconoclast

Reputation: 22680

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)

Upvotes: 31

dc-
dc-

Reputation: 1936

To toggle, use the following:

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

Upvotes: 24

jamapag
jamapag

Reputation: 9318

In my .vimrc I have:

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

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

Upvotes: 58

Related Questions