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
eve开发者_如何转开发ry time I want to enable it. So I'd like to type :nr
or something like that. Is that possible?
In my .vimrc
I have:
let mapleader = ","
nmap <leader>ne :NERDTree<cr>
So when I need NERDTree I just write ,ne
in normal mode.
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.
- It works in both normal and insert mode
- 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)
To toggle, use the following:
map <silent> <C-n> :NERDTreeToggle<CR>
For ex Sublime users:
map <silent> <C-k>b :NERDTreeToggle<CR>
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"
精彩评论