I would like to capture the result of a shell command into a vim variable inside of my vimrc file.
I tried using let myvar = system("DIR")
however it seems to crash vim when I put it in my vimrc file. I launch vim and then it just returns immediately without any error message.
So instead I was wondering if I can do something like let exe_path = <expr> :!pwd
? This is obviously the wrong way to do it so I was wondering if something like that is possible?
system()
command should work. Questions is, what you mean with it is crashing vim. That should not happen.let myvar = system('pwd')
is the way to go as described in this duplicate question on my system it works fine. I think you used the wrong tag and meantmicrosoft-windows
so are you sure your Windows shell supportspwd
(it's been a long time since I haven't used a windows shell so I don't remember if it's supported) maybe you should try with another command ?system()
definitely is the function you're looking for; rather than asking for an alternative, please post more details about that "crash".:autocmd VimEnter * let myvar = system('pwd')
; it's still on startup, but at the end of it.let myvar = getcwd()
makes more sense thansystem()
.