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()
" Start NERDTree and leave the cursor in it.
autocmd VimEnter * NERDTree
" Start NERDTree and put the cursor back in the other window.
autocmd VimEnter * NERDTree | wincmd p
" Start NERDTree when Vim is started without file arguments.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif
" Start NERDTree. If a file is specified, move the cursor to its window.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif
" Start NERDTree, unless a file or session is specified, eg. vim -S session_file.vim.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists('s:std_in') && v:this_session == '' | NERDTree | endif
" Start NERDTree when Vim starts with a directory argument.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') |
\ execute 'NERDTree' argv()[0] | wincmd p | enew | execute 'cd '.argv()[0] | endif
7条答案
按热度按时间8fq7wneg1#
在你的vimrc应该做的
:他autocmd.txt作为背景
1l5u6lss2#
您也只能在命令行中没有文件时打开Nerd Tree:
取自blog post by Ovid。
uwopmtnx3#
一个用于在未提供文件参数时打开NERDTree的行程序
上面的代码只是检查是否没有提供参数,然后打开
NERDTree
。fv2wmkja4#
基于@zoul的回答,我希望NERDTree在指定目录或不指定任何内容时默认打开,而在指定单个文件时不打开,因此我得到了:
iqjalb3h5#
如果你正在寻找一种方法来拥有一个持久的NERDTree,即使你打开新的标签页,它也会保持不变,你最好使用jistr/vim-nerdtree-tabs并在你的
.vimrc
中添加:这个包不再维护了,但是它可以工作,我不知道有什么等价的。
vshtjzan6#
在你的vim配置文件中(我使用nvim,所以对我来说是
~/.config/nvim/init.vim
),在文件中的任意位置添加以下行:
au VimEnter * NERDTree
piv4azn77#
NERDree文档中有官方答案。
https://github.com/preservim/nerdtree#how-do-i-open-nerdtree-automatically-when-vim-starts