How can I keep the color when I run the external command inside vim?

For example, for the command ls --color displays colorful results when being executed in the shell. However, when I call :!ls --color inside vim, all color information is gone.

What should I do to keep the color when calling external command inside vim?

EDIT: To clarify my question, This is a question about VIM itself, I'm NOT actually asking how to enable "ls"'s color. What I want to know is, generally how to enable the display of colorful results of ALL shell commands(as long as they have colorful results).


Solution 1:

CLI Vim or GUI Vim?

You can't show the output of :!ls or :!ls --color or any other external command in CLI Vim itself because it's single threaded: Vim is suspended and $ ls --color is executed in your shell. There's no way around that. Well, you can place the output of external commands in the current buffer but that's not the same thing.

In GUI Vim, you can only get a pseudo-shell that is totally unable to show any colors. There's no way around that either.

If you desperately need colored output from external commands you have to launch an external terminal emulator with something like :!xterm & or use a plugin like Conque Shell.

Solution 2:

You can :set shellcmdflag=-ic to make the shell behave interactively, like your command prompt.