简体   繁体   English

在 vim 中自动打开 NERDTree

[英]Auto-open NERDTree in vim

Does someone know how to force .vimrc to auto-open NERDTree each time vim is invoked?有人知道每次调用 vim 时如何强制 .vimrc 自动打开 NERDTree 吗? The operation system is *nix.操作系统是*nix。

 au VimEnter *  NERDTree

in your vimrc should do it 在你的vimrc中应该做到这一点

:he autocmd.txt for background :he autocmd.txt为背景

You can also only open Nerd Tree when there was no file on the command line: 您也只能在命令行上没有文件时打开书呆子树:

function! StartUp()
    if 0 == argc()
        NERDTree
    end
endfunction

autocmd VimEnter * call StartUp()

Taken from a blog post by Ovid . 摘自Ovid博客文章

One liner to open NERDTree when no file argument provided would be 当没有提供文件自变量时,一个衬里打开NERDTree

autocmd vimenter * if !argc() | NERDTree | endif
OR
au vimenter * if !argc() | NERDTree | endif

The above code just checks if no argument is provided then open NERDTree . 上面的代码只是检查是否没有提供参数,然后打开NERDTree

Building on @zoul's answer, I in my case I wanted NERDTree to be open by default if I specify a directory or if I specify nothing, and not be open if I specify a single file, so I ended up with: 以@zoul的答案为基础,在我的情况下,如果我指定目录或不指定内容,我希望NERDTree在默认情况下处于打开状态,而在指定单个文件时不处于打开状态,因此我得到了:

function! StartUp()
    if !argc() && !exists("s:std_in")
        NERDTree
    end
    if argc() && isdirectory(argv()[0]) && !exists("s:std_in")
        exe 'NERDTree' argv()[0]
        wincmd p
        ene
    end
endfunction

autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * call StartUp()

If you are looking for a way to have a persistent NERDTree, that remains even when you open new tabs, you'd better use jistr/vim-nerdtree-tabs and add in your .vimrc :如果您正在寻找一种拥有持久 NERDTree 的方法,即使您打开新标签页,它仍然存在,您最好使用jistr/vim-nerdtree-tabs并添加您的.vimrc

let g:nerdtree_tabs_open_on_console_startup=1

The package is not maintained anymore, but it works and I don't know any equivalent.该软件包不再维护,但它有效,我不知道任何等效项。

In your vim config file (I use nvim, so for me its in ~/.config/nvim/init.vim ),在你的 vim 配置文件中(我使用 nvim,所以对我来说它在~/.config/nvim/init.vim ),
Add the line anywhere in the file: au VimEnter * NERDTree在文件中的任意位置添加一行: au VimEnter * NERDTree

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

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