0

The command that produces weird output:

$ vim -ec 'call writefile(["line1","line2"],"/proc/self/fd/9") | qall!' 9>&1 1>/dev/null 2>&1
line1
     line2
          $

Same command piped to cat to check for terminal control sequences:

$ vim -ec 'call writefile(["line1","line2"],"/proc/self/fd/9") | qall!' 9>&1 1>/dev/null 2>&1 | cat -A
line1$
      line2$
            $

Passing -s (ex silent mode) to vim seems to fix the problem, but I can't use this switch because I can't get syntax highlighting with this mode...

$ vim -esc 'call writefile(["line1","line2"],"/proc/self/fd/9") | qall!' 9>&1 1>/dev/null 2>&1 | cat -A
line1$
line2$
$

Furthermore, if you pipe the output to less and redraw (Ctrl-L) the screen, everything aligns correctly!

After consulting the source code of Vim, I've also written a little C program to simulate what Vim does, but I could not reproduce the same behaviour with my program.

So, why we have such behaviour in this situation and how to fix it?

  • It's because vim has set your terminal to raw mode while it works - the output isn't weird at all, it just doesn't have any inserted returns. do stty -opost in your shell's terminal and watch what happens. – mikeserv Jul 16 '15 at 8:19
  • Why would you want syntax highlighting while running vim in what's essentailly batchmode? – wurtel Jul 16 '15 at 11:18
  • @wurtel, I am trying to use vim as a syntax highlighter for less filter. – cychoi Jul 16 '15 at 20:57
  • @cychoi OK, creative :) – wurtel Jul 17 '15 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.