In VIM how to make NERDTree open at startup nicely when giving args -
let me explain question, want is:
from command line calling
gvim
without arguments, want nerdtree open default in/home/user/documents
folder.from command line calling
gvim .
want open nerdtree directory set actual directory command executed from. still want nerdtree on left , empty buffer in right (not nerdtree being window happens).from command line calling
gvim /some/path/to/folder
want open nerdtree directory set given directory. still want nerdtree on left , empty buffer in right (not nerdtree being window happens).when calling
gvim
argument:- if file, don't open nerdtree file.
- if directory nerdtree should work
#3
to address #1
have:
function! startup() if 0 == argc() nerdtree ~/documents endif endfunction autocmd vimenter * call startup() autocmd vimenter * wincmd p
what thinking address #2
, #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 doesn't work, gives me errors , vim freezes times. can achieve desired effect?
thanks help.
complete solution
does not work expected it's very close. far 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
i can't give complete solution, here's hint should resolve errors:
the :nerdtree
command takes (optional) directory; doesn't resolve expressions. vim's evaluation rules different programming languages. need use :execute
in order evaluate variable (or expression); otherwise, it's taken literally; i.e. vim uses variable name argument. change this:
nerdtree expand(getcwd())
into:
execute 'nerdtree' getcwd()
i've left out expand()
, getcwd()
returns full path.
Comments
Post a Comment