I am trying to write a wrapper shell script that is supposed to launch vim with a vimwiki in current directory:


gvim -c "let g:vimwiki_list = [{'path': '$PWD/'}] | normal ,ww"

The normal command works (the comma is my custom remapped <Leader>), but it doesn't honor the custom path option.

To reproduce the problem, just run the above script somewhere not in home directory. At startup, vim will ask to create ~/vimwiki instead of using current working directory. Yet after I skip that question and do

:echo g:vimwiki_list

in vim's command line, it displays the correct current directory. So it's not a problem of the correct value of $PWD getting passed to vim, I use the bash variable inside double quotes so this part is fine.

How to debug and eventually fix it?

I had a customized g:vimwiki_list in my vimrc, but I also tried with defaults by commenting that part, the problem still persists (Is it true that settings passed via command line the way I did aren't overwritten by the ones hardcoded in vimrc anyway?).

1 Answer 1


The commands given with -c are executed after the first file is loaded. I guess that at that time, vimwiki is already initialized and asked for creation of the directory ~/vimwiki.

Use --cmd .... This commands are executed before vimrc is loaded. So the variable should be set at the time vimwiki is initializing.


gvim --cmd "let g:vimwiki_list = [{'path': '$PWD/'}]" -c "normal ,ww"

So g:vimwiki_list is assigned before vimrc is sourced and ,ww is executed after the first file was loaded.

See :help --cmd and :help -c.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.