开发者

Getting rid of ANSI escape characters when viewing ri in (Mac)Vim

开发者 https://www.devze.com 2023-02-06 00:10 出处:网络
I\'m having trouble viewing ri documentation within gvim and MacVim (tried it on both) Some of the ri documentation includes text decorations that look fine when viewed in a terminal window, but inclu

I'm having trouble viewing ri documentation within gvim and MacVim (tried it on both) Some of the ri documentation includes text decorations that look fine when viewed in a terminal window, but include ANSI escape characters when viewing in gvim/MacVim. For example, the following ri snippet from $ri class looks like this in the terminal:

Returns the class of obj, now preferred over Object#开发者_JAVA技巧type

And this in gvim:

Returns the class of [4mobj[m, now preferred over [7mObject#type[m,

It'd be great to be able to reference legible ri docs within gvim. Any ideas on where to begin looking to fix this?


Try running ri like this:

ri --format=rdoc

AFAIK, the rdoc format is plain text so you won't have to filter out the ANSI escape sequences.

You can probably get "real" plain text by making a shell script like this:

ri --format=bs $@ | sed 's:.^H::g'

Where ^H is a raw Ctrl-H (or whatever backspace is for you), then call that shell script instead of ri.


These two scripts seem to have been written to address that problem. They don't appear to be perfect solutions. One of them apparently requires a patch to vi, or did at one point. I can't quite tell what the other one does but I think it renders your window, interpreting the codes, when you use a specific command.

There is also some advice on existing vi commands.

See:

  • http://www.vim.org/scripts/script.php?script_id=302

  • http://www.vim.org/scripts/script.php?script_id=1127

0

精彩评论

暂无评论...
验证码 换一张
取 消