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?
Create a command shortcut for NERDTree in Vim editor
Asked Answered
Note: Vim doesn't let you add custom commands that start with a lowercase. For Instance, ':ne' would not be valid, but ':Ne' would be. –
Photocell
In my .vimrc
I have:
let mapleader = ","
nmap <leader>ne :NERDTree<cr>
So when I need NERDTree I just write ,ne
in normal mode.
If you want do it like in your question, then add to
.vimrc
: :command NE NERDTree
. Than you can call it: :NE
–
Fact Thanks! I've been using
nmap <leader>ne :NERDTreeToggle<cr>
to toggle NERDTree on and off. –
Archuleta Why isn't this a default =( –
Wera
It would be nice is this focused in NERDtree if it was already open. –
Wera
@Fact if you have no object, you should make this
:NERDTreeFocus
so it doesn't open multiple copies. –
Wera 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)
For me in INSERT mode Control-N was always code completion. And it stil is with this mapping. –
Yalonda
To toggle, use the following:
map <silent> <C-n> :NERDTreeToggle<CR>
this solution is very practical –
Primine
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"
.vimrc:
let mapleader = "n" #nerdtree
nmap <leader> :NERDTreeFocus<cr>
let mapleader = "f" #focus
nmap <leader> :NERDTreeToggle<cr>
.bash_profile:
alias n="vim -c 'NERDTree'"
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. –
Hua
© 2022 - 2024 — McMap. All rights reserved.