简体   繁体   English

在 Vim 编辑器中为 NERDTree 创建命令快捷方式

[英]Create a command shortcut for NERDTree in Vim editor

I'd like to create an abbreviation for NERDTree on the command-line.我想在命令行上创建 NERDTree 的缩写。 I find it annoying have to write :NERDTree every time I want to enable it.我觉得每次我想启用它时都必须写:NERDTree很烦人。 So I'd like to type :nr or something like that.所以我想输入:nr或类似的东西。 Is that possible?那可能吗?

In my .vimrc I have:在我的.vimrc我有:

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

So when I need NERDTree I just write ,ne in normal mode.因此,当我需要 NERDTree 时,我只需在正常模式下编写,ne

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.您只需按 control-n 即可返回层次结构。 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)它不会像接受的答案那样关闭层次结构(使用:NERDTree命令从头开始,关闭层次结构,而使用:NERDTreeFocus只是移动焦点,我认为这就是您想要的)

要切换,请使用以下命令:

map <silent> <Cn> :NERDTreeToggle<CR>

对于前 Sublime 用户:

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

add to your rc file (.bashrc / .zshrc) this shortcut将此快捷方式添加到您的 rc 文件(.bashrc / .zshrc)中

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

then, reload your bash width然后,重新加载您的 bash 宽度

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

and run并运行

nerd

the -c flag allows you to execute a command when starting the terminal -c标志允许您在启动终端时执行命令

nvim -c "command"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM