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. – Christian Brabandt Nov 28 '19 at 10:37let 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-windowsso 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 ? – statox Nov 28 '19 at 10:37system()definitely is the function you're looking for; rather than asking for an alternative, please post more details about that "crash". – Ingo Karkat Nov 28 '19 at 10:38let myvar = system("DIR")while vim was running, and it works well. The problem is when I put that same line inside of my vimrc file. What happens when I reload vim is that it simply shuts down immediately. I entervim.exethen press enter and the console simply returns back right away without any error message. – mbl Nov 28 '19 at 11:50:autocmd VimEnter * let myvar = system('pwd'); it's still on startup, but at the end of it. – Ingo Karkat Nov 28 '19 at 12:33let myvar = getcwd()makes more sense thansystem(). – Matt Nov 28 '19 at 12:45