使用emacs或vim的命令行程序的语法荧光笔? [英] Utilizing emacs' or vim's syntax highlighter for command-line program?

查看:174
本文介绍了使用emacs或vim的命令行程序的语法荧光笔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个命令行程序,可以发布JSON和YAML。默认情况下,它会检测到pygments(pygmentize)是否可用,如果是,则将输出传递给它以获得很好的着色输出。但是,在程序运行的大多数计算机上,默认情况下不会安装pygments。但大多数电脑都会使用emacs或vim,但是。有没有办法让这些编辑器之一进行语法 - 使用ANSI转义序列突出显示一些文本,然后再次输出?

解决方案

Matthew Wozniski写了一个名为vimcat.sh的脚本,它与Vim一起使用。他的版本是 https://github.com/godlygeek/vim -files /斑点/主/宏/ vimcat.sh 。我已经做了一些修改(如果内存服务,这些修改允许它在我的Mac OS X系统上运行;我知道替换为 / dev / fd / 9 / proc / self / fd / 9 有此目的);请参阅 https://gist.github.com/4090959 上的要点。



如果Vim的突出显示改变背景,我相信脚本的两个版本都有麻烦返回默认的背景颜色。


I have a command-line program that spews JSON and YAML. By default it detects if pygments (pygmentize) is available and if it does, pass the output throught it to get a nice colorized output. However, pygments is not installed by default on most computers that this program will run on. But most computers will have either emacs or vim, however, does. Is there a way to get one of these editors to syntax-highlight some text using ANSI escape sequences and then output it again?

解决方案

Matthew Wozniski wrote a script called vimcat.sh that does this with Vim. His version is at https://github.com/godlygeek/vim-files/blob/master/macros/vimcat.sh. I've made a few modifications to it (if memory serves, the modifications allowed it to run on my Mac OS X system; I know the substitution of /dev/fd/9 for /proc/self/fd/9 had that purpose); see my gist at https://gist.github.com/4090959.

I believe both versions of the script have trouble with returning to default background color if Vim's highlighting changes the background.

这篇关于使用emacs或vim的命令行程序的语法荧光笔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆