vim AnsiEsc脚本

警告
本文最后更新于 2023-03-09,文中内容可能已过时。

背景

在使用gitea的时候配置了彩色日志,使用tail查看日志是彩色的,但是用vim打开,就像一堆乱码。这可怎么办呢?

使用tail命令查看是这样的:

image-20230103225448640

使用vim打开是这样的:

image-20230103225635425

解决方案:

AnsiEsc.vim : ansi escape sequences concealed, but highlighted as specified (conceal)

created by: Charles Campbell

script type: syntax

description:
Files with ANSI escape sequences look good when dumped onto a terminal that accepts them, but heretofore have been a distracting clutter when edited via vim. The AnsiEsc.vim file, when sourced with vim 7.3 or later, will conceal Ansi escape sequences but will cause subsequent text to be colored as the escape sequence specifies.

You need to have a vim with conceal mode enabled; use has(“conceal”) to find out if the vim you’re using has that feature.

Without that conceal feature or with vim versions earlier than 7.3, the best that can be done is to suppress Ansi escape sequences with “Ignore” highlighting. AnsiEsc.vim v2 does that.

Cutting edge versions are available at http://www.drchip.org/astronaut/vim/index.html#ANSIESC .

Usage: edit a file containing escape sequences, then type :AnsiEsc

install details:

1
2
3
vim AnsiEsc.vba.gz
:so %
:q

第一步到vim官网下载AnsiEsc脚本

vim/AnsiEsc

image-20230103225936033

第二步安装AnsiEsc

1
vim AnsiEsc.vba.gz

image-20230103230153910

1
:so %

image-20230103230306848

接着按回车

image-20230103230357830

1
:q

第三步启用AnsiEsc

再用vim打开日志文件输入:

1
:AnsiEsc

image-20230103230710529

这看起来就舒服多了!

Buy Me a Coffee ~~
hiifong 支付宝支付宝
hiifong 微信微信
0%