linux 在体内自动打开NERDree

w1jd8yoj  于 2023-03-07  发布在  Linux
关注(0)|答案(7)|浏览(129)

有人知道如何强制.vimrc在每次调用vim时自动打开NERDree吗?操作系统是 *nix。

8fq7wneg

8fq7wneg1#

au VimEnter *  NERDTree

在你的vimrc应该做的
:他autocmd.txt作为背景

1l5u6lss

1l5u6lss2#

您也只能在命令行中没有文件时打开Nerd Tree:

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

autocmd VimEnter * call StartUp()

取自blog post by Ovid

uwopmtnx

uwopmtnx3#

一个用于在未提供文件参数时打开NERDTree的行程序

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

上面的代码只是检查是否没有提供参数,然后打开NERDTree

fv2wmkja

fv2wmkja4#

基于@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()
iqjalb3h

iqjalb3h5#

如果你正在寻找一种方法来拥有一个持久的NERDTree,即使你打开新的标签页,它也会保持不变,你最好使用jistr/vim-nerdtree-tabs并在你的.vimrc中添加:

let g:nerdtree_tabs_open_on_console_startup=1

这个包不再维护了,但是它可以工作,我不知道有什么等价的。

vshtjzan

vshtjzan6#

在你的vim配置文件中(我使用nvim,所以对我来说是~/.config/nvim/init.vim),
在文件中的任意位置添加以下行:au VimEnter * NERDTree

piv4azn7

piv4azn77#

NERDree文档中有官方答案。
https://github.com/preservim/nerdtree#how-do-i-open-nerdtree-automatically-when-vim-starts

" 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

相关问题