system() with powershell in vim

前端 未结 2 510
旧时难觅i
旧时难觅i 2021-01-05 16:55

I\'m trying to write a simple function in Vim to return the results of a powershell command. I keep getting gibberish in the results though.

I think this may be an

2条回答
  •  [愿得一人]
    2021-01-05 17:33

    Try instead set shellcmdflag=\ -c

    Explanation:

    Vim uses tempname() to generate a temp file path that system() reads.

    If &shell contains 'sh' and &shellcmdflag starts with '-' then tempname() generates a temp file path with forward slashes.

    Thus, if set shell=powershell set shellcmdflag=-c then Vim will try to read a temp file with forward slashes that cannot be found.

    A remedy is to set instead set shellcmdflag=\ -c that is, add a whitespace to &shellcmdflag so that the first character is no longer '-' and tempname() produces a temp file path with backward slashes that can be found by system().

提交回复
热议问题