7

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.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
  • possible duplicate of [Bad command output in MacVim](http://stackoverflow.com/questions/4765378/bad-command-output-in-macvim) – Chris Johnsen Sep 20 '11 at 01:43

5 Answers5

4

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.

sehe
  • 374,641
  • 47
  • 450
  • 633
2

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>

avocade
  • 1,313
  • 1
  • 14
  • 19
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.

clt60
  • 62,119
  • 17
  • 107
  • 194
  • While interesting, I don't expect this answers the question. I think the 'echo' with ANSI escapes was just a minimal example of what he means. Usually, what really transpires is a `git diff` with color enabled, or `make`,`diff`,`gcc` being symlinked to color{make,diff,gcc} etc – sehe May 25 '11 at 15:30
  • @sehe, @jm666: Yes, the ANSI is a minimal example, though this is helpful. In any case, though, when I tried the example in MacVim it didn't print in color. – Brian M. Hunt May 25 '11 at 15:48
1

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.

kikito
  • 51,734
  • 32
  • 149
  • 189
  • 1
    If you're running in console mode it's probably better to simply suspend the process (ctrl + z), execute the command and then bring vim's process back (run `fg`). – Ciro Costa Jan 21 '16 at 14:14
0

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.

ZyX
  • 52,536
  • 7
  • 114
  • 135