VIM Unix commands printed in color

爷,独闯天下 提交于 2019-12-30 18:26:23

问题


I'm using MacVim and I would like to have ! commands printed in color. For example:

In bash, the following echo statement prints Hello World in green (as expected):

$ echo -e "\033[32m Hello World" 
 Hello World

However, in VIM the output is not color, and the escape codes are printed:

:!echo -e "\033[32m Hello World" 
 [32m Hello World

How can one have VIM (and MacVim build 57 in particular) print the output of ! commands and honour ANSI color escapes.


回答1:


You can't. But you can suspend the editor and drop to a shell relatively quickly;

Or you can use Ansi Filter to remove the escape sequences so you will at least not see a mess.




回答2:


this one:

:!echo $(tput setaf 1)Hello world$(tput sgr0)

will print Hello world in color.

Don't use escape sequences, but named tput entries. (all times, not only in this example). read:
man teminfo; man infocmp; man tput - for more information.

based on comments I found this question very interesting.

Still searching for the better solution, but for now find this one - http://code.google.com/p/conque/ . Allow run colored commands inside MacVim's buffer.




回答3:


Don't know if this would help, but running my RSpec tests inside vim gives me colored output using the --color option. I use the following command to run the current spec file inline:

:map ,t :w\|:!rspec --color %<cr>




回答4:


If you run macvim in console mode (vim, not mvim) all :! commands are redirected to the shell and executed there. They take the whole window instead of 1/3 of it, and they use whatever theme your console happens to have.

But you get ansicolors.




回答5:


Your question (and its pop up done by @avocade) addressed the issue I have with some printing in my aurum plugin thus I’ve wrote (started to write, but the most significant piece of functionality is already here) the ansi_esc_echo plugin. To use it in your one you must install it, install frawor and do

execute frawor#Setup('0.0', {'autoload/ansi_esc_echo': '0.0'})
call s:_r.ansi_esc.echo("\e[33mabc")

. Currently it deals only (speaking exclusively about special characters or sequences) with carriage return, backspace (untested), tab, newline, and CSI colors.



来源:https://stackoverflow.com/questions/6126575/vim-unix-commands-printed-in-color

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!