17

I'm trying to view and edit a file in Vim, but this file has ANSI escape codes:

^[[1m[0.05s elapsed, 00:00:13 total]^[[0m

How can I tell Vim to interpret them properly instead of just showing the raw code?

Nathan Fellman
  • 9,372
  • 20
  • 62
  • 82
  • 2
    What does "interpret properly" mean? – wallyk Nov 17 '11 at 09:30
  • Related: http://unix.stackexchange.com/questions/7695/how-to-make-vim-display-colors-as-indicated-by-color-codes (not dupe because he wants Vim as a pager) – Ciro Santilli OurBigBook.com Mar 23 '14 at 15:18
  • @wallyk: It means I want to see colors and effects, not raw codes. – Nathan Fellman Mar 23 '14 at 20:44
  • See the answer at https://vi.stackexchange.com/a/20496/3324: *“If you have a sufficiently modern vim that has the +terminal feature, you can do `:term cat somefile` and you'll get a buffer with all the terminal codes interpreted. This might work better on large files than e.g. Colorizer, which made my vim unusably slow when I let it loose on a 6000-line file.”* – sideshowbarker Dec 07 '19 at 17:10

1 Answers1

17

It sounds like you want to display ANSI colors and conceal their escape characters. You can do this with Charles Campbell's "AnsiEsc" plugin.

Note that you will need Vim version 7.3 or newer. (Older versions of Vim could be patched, but that's more work for an outdated version of Vim.)

Heptite
  • 19,383
  • 5
  • 58
  • 71
  • This works, if the file is in a buffer. However it doesn't work great if you are running a command like rake or cucumber that puts the command output not in a buffer. – Ivan -Oats- Storck Jan 30 '12 at 05:50
  • That is correct, but the asker specifically mentioned ANSI within a file opened in Vim. – Heptite Jan 30 '12 at 06:51