Using vim to syntax highlight stdin

926 views
Skip to first unread message

Scott

unread,
May 20, 2012, 7:36:02 PM5/20/12
to vim...@googlegroups.com
I know I'm trying to abuse Vim in ways it's not supposed to be used, but I'm just wondering if this is possible ...

Is there any way to configure vim to syntax highlight stdin & NOT paginate?

eg. ./myprog | vim --insert-magic-here

The less.sh script does all the syntax highlighting I want, but it paginates it's output which I do not want.

Scott. :)

Ben Fritz

unread,
May 21, 2012, 10:55:33 AM5/21/12
to vim...@googlegroups.com

You will probably need to set the filetype manually, but Vim can easily handle stuff from stdin. E.g.

./myprog | vim -c "setl filetype=myfiletype" -

Dominique Pellé

unread,
May 21, 2012, 2:25:33 PM5/21/12
to vim...@googlegroups.com
Vim can automatically detect file files from stdin for some file types
by looking at the content. This is done in $VIMRUNTIME/scripts.vim.

It should work for xml files for example:

$ vim - < foo.xml

-- Dominique

Scott

unread,
May 21, 2012, 11:46:02 PM5/21/12
to vim...@googlegroups.com
I hope this doesn't sound ungrateful, but that doesn't answer my question at all!

My question is about preventing pagination. I'd like to use Vim syntax highlighting to highlight my program output but I do NOT want to Vim to paginate the output.

Is there any way to configure Vim's less.sh script NOT to paginate it's output?

Thanks,

Scott. :)

Magnus Woldrich

unread,
May 22, 2012, 12:14:50 AM5/22/12
to vim...@googlegroups.com
On May 22, Scott (Scott) wrote:
>My question is about preventing pagination. I'd like to use Vim syntax
>highlighting to highlight my program output but I do NOT want to Vim to
>paginate the output.

You want the data highlighted on stdout?

https://github.com/trapd00r/utils/blob/master/v

--
Magnus Woldrich
m...@japh.se, wold...@cpan.org
irc: scp1 on freenode
uri: http://japh.se

Scott

unread,
May 22, 2012, 2:57:50 AM5/22/12
to vim...@googlegroups.com
Hi Magnus,

Ah! Yes, me want! :)

Is there any way to get it to read from stdin?

eg. ./myprog | blob.vim -c "setl filetype=log" -

Also, the syntax highlighting has a bug:

Highlighting in Vim: http://www.tiikoni.com/tis/view/?id=70b54d5
Highlighting in Blob: http://www.tiikoni.com/tis/view/?id=9315eef

Scott. :)

Scott

unread,
May 22, 2012, 3:02:49 AM5/22/12
to vim...@googlegroups.com
Here's my syntax highlighting config in case it's useful.

http://pastebin.com/DapNxcJY

Scott. :)

Magnus Woldrich

unread,
May 22, 2012, 3:10:30 AM5/22/12
to vim...@googlegroups.com
On May 22, Scott (Scott) wrote:
>Is there any way to get it to read from stdin?
>
>eg. ./myprog | blob.vim -c "setl filetype=log" -

What's blob.vim?

With the script I linked, just do something like

v '-c set ft=log' -

Scott

unread,
May 22, 2012, 5:23:45 AM5/22/12
to vim...@googlegroups.com
blob.vim *IS* v.

It doesn't appear to be able to read from stdin.

Scott.

Matt Martini

unread,
May 22, 2012, 3:39:36 PM5/22/12
to vim...@googlegroups.com, mag...@trapd00r.se
On May 22, 2012, at 12:14 AM, Magnus Woldrich wrote:

On May 22, Scott (Scott) wrote:
My question is about preventing pagination. I'd like to use Vim syntax
highlighting to highlight my program output but I do NOT want to Vim to
paginate the output.

You want the data highlighted on stdout?

https://github.com/trapd00r/utils/blob/master/v


Magnus,

Nice job with v.  However, it doesn't work under OSX (10.6.8 Snow Leopard) (it does in linux).

I'm pretty sure its because STDOUT is not /proc/self/fd/9 on OSX.  I tried /dev/fd/1 but this didn't work.

return writefile(retv, '/proc/self/fd/9')

Could you provide a patch for OSX? 

Thanks

Matt

Reply all
Reply to author
Forward
0 new messages