Skip to content

Instantly share code, notes, and snippets.

@retorillo
Last active March 8, 2017 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retorillo/9af7351b4e76d4bc8b04de43795f6569 to your computer and use it in GitHub Desktop.
Save retorillo/9af7351b4e76d4bc8b04de43795f6569 to your computer and use it in GitHub Desktop.

Vim Script cross-platform scripting between Windows and Linux

Test Environment

  • Vim 8 on Windows 10 (from chocolatey)
  • Vim 7 on Bash on Ubuntu on Windows 10

system()

echo system('(echo foo) && (echo bar)')

Windows prints only bar (last command result) Linux prints foo and bar

To solve this incompatibility, surround entire commands

echo system('((echo foo) && (echo bar))')

Then, both Windows and Linux returns foo and bar.

systemlist()

echomsg systemlist('((echo foo) & (echo bar))')

systemlist() cannot remove carridge return.

Windows returns ['foo\r', 'bar\r'] Linux returns ['foo', 'bar']

Should be

split(system('...'), '\v\r?\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment