Let me explain my question, what I want to do is:
From the command line calling
gvim
without arguments, want NERDTree open by default in my/home/user/Documents
folder.From the command line calling
gvim .
want to open NERDTree with the directory set to the actual directory where the command was executed from. BUT I still want NERDTree on the left and a empty buffer in the right (not NERDTree being the only window just like normally happens).From the command line calling
gvim /some/path/to/folder
want to open NERDTree with the directory set to the given directory. BUT I still want NERDTree on the left and a empty buffer in the right (not NERDTree being the only window just like normally happens).When calling
gvim
with an argument:- If it is a file, don't open NERDTree just the file.
- If it is a directory NERDTree should work as
#3
To address #1
I have:
function! StartUp()
if 0 == argc()
NERDTree ~/Documents
endif
endfunction
autocmd VimEnter * call StartUp()
autocmd VimEnter * wincmd p
What I was thinking to address #2
and #3
was:
function! StartUp()
if 0 == argc()
NERDTree ~/Documents
else
if argv(0) == '.'
NERDTree expand(getcwd())
else
NERDTree expand(argv(0))
endif
endif
endfunction
autocmd VimEnter * call StartUp()
autocmd VimEnter * wincmd p
But it doesn't work, it gives me errors and vim freezes some times. What I can do to achieve the desired effect?
Thanks for your help.
Complete solution
Does not work exactly as I expected but it's very very close. So far so god.
function! StartUp()
if 0 == argc()
NERDTree ~/Documents
else
if argv(0) == '.'
execute 'NERDTree' getcwd()
else
execute 'NERDTree' getcwd() . '/' . argv(0)
endif
endif
endfunction
autocmd VimEnter * call StartUp()
autocmd VimEnter * wincmd p