简体   繁体   中英

Vim treatment vimrc if folder

I'm currently working on my .vimrc, and theres is something i don't know about.

I made this line :

"=====[ On vim load, toggle NERDTree and switch to file ]=====        
autocmd VimEnter * :NERDTreeToggle | wincmd l

Which open nerdtree on load when i open vim, then switch to the main buffer after.

This work nice, but i want this cmd only when I open a folder :

vim .

But when I'm working on file only I don't need it.

vim mytext.md

I'm looking for a condition on my rc file, but I don't find it. Something like :

"=====[ On vim load, toggle NERDTree and switch to file ]=====        
if typefile != 'file'

autocmd VimEnter * :NERDTreeToggle | wincmd l

endif

So if you have an idea on this...

thanks for all

This should work:

augroup vimrc
    autocmd!
    autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) | NERDTreeToggle | wincmd l | endif
augroup END

But I'm sure there's already a definitive solution somewhere on the internet.

See :help argc() , :help argv() and :help isdirectory() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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