0

Goal: print git diffs of pwd in a popup

let diff = system('git diff')
call popup_create(diff, {})

Problem: It prints ^@(I've got to know that is newline chars):

diff --git a/.config/fish/config.fish b/.config/fish/config.fish^@deleted file mode 100644^@...(ellipsis)

How could I escape the newline chars in the variable diff?

I tried substitute and it does not work:

let diff = system('git diff')
let diff = substitute(diff, '^@', '\n', 'g')
call popup_create(diff, {})

1 Answer 1

2

I don't know if it's documented, but if I see ^@ in the output because of newlines, what I'd do is see if a list of strings is allowed instead, and if so, the split the string on newline and pass that list instead:

:call popup_create(split(diff, "\n"), {})

It seems popup_create() does support a list of strings, so I'd expect this to then show the output the way you expect to see it.

2
  • 3
    Also see systemlist()
    – D. Ben Knoble
    Commented Mar 18, 2022 at 13:07
  • I second the systemlist() approach Commented Mar 19, 2022 at 16:25

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.