# vim AnsiEsc脚本


## 背景

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

**使用`tail`命令查看是这样的：**

![image-20230103225448640](https://img.nil.lc/img/202301032254716.png)

**使用`vim`打开是这样的：**

![image-20230103225635425](https://img.nil.lc/img/202301032256490.png)



## **解决方案：**

&gt; **AnsiEsc.vim : ansi escape sequences concealed, but highlighted as specified (conceal)**
&gt;
&gt; **created by:** [Charles Campbell](https://www.vim.org/account/profile.php?user_id=96)
&gt;
&gt; **script type:** syntax
&gt;
&gt; **description:**
&gt; 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.
&gt;
&gt; You need to have a vim with conceal mode enabled; use has(&#34;conceal&#34;) to find out if the vim you&#39;re using has that feature.
&gt;
&gt; 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 &#34;Ignore&#34; highlighting.  AnsiEsc.vim v2 does that.
&gt;
&gt; Cutting edge versions are available at http://www.drchip.org/astronaut/vim/index.html#ANSIESC .
&gt;
&gt; **Usage:**  edit a file containing escape sequences, then type `:AnsiEsc`
&gt;
&gt; **install details:**
&gt;
&gt; ```bash
&gt; vim AnsiEsc.vba.gz
&gt; :so %
&gt; :q
&gt; ```

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

[vim/AnsiEsc](https://www.vim.org/scripts/script.php?script_id=302)

![image-20230103225936033](https://img.nil.lc/img/202301032259107.png)

### 第二步安装`AnsiEsc`

```bash
vim AnsiEsc.vba.gz
```

![image-20230103230153910](https://img.nil.lc/img/202301032301957.png)

```bash
:so %
```

![image-20230103230306848](https://img.nil.lc/img/202301032303881.png)

接着按回车

![image-20230103230357830](https://img.nil.lc/img/202301032303867.png)

```bash
:q
```

### 第三步启用`AnsiEsc`

再用`vim`打开日志文件输入：

```bash
:AnsiEsc
```

![image-20230103230710529](https://img.nil.lc/img/202301032307596.png)

这看起来就舒服多了！



---

> 作者: hiifong  
> URL: https://f.style/ansiesc/  

