开发者

Create a command shortcut for NERDTree in Vim editor

开发者 https://www.devze.com 2023-03-14 23:38 出处:网络
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

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.

  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)


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"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号