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).

  • 2
    Works fine here. – Ignacio Vazquez-Abrams Jul 16 '12 at 20:01
  • 1
    "This is a question about VIM itself ..." – Ignacio Vazquez-Abrams Jul 17 '12 at 1:10
  • 2
    and vim is one of the "software tools commonly used by programmers"... – CMinus Jul 17 '12 at 1:18
  • 1
    So's email. Doesn't necessarily mean "how do I Thunderbird" is on topic here. – Ignacio Vazquez-Abrams Jul 17 '12 at 2:14
  • 2
    Vim has ctags, indent and much more direct support for programming. Email does what directly for programming? – Jens Jul 17 '12 at 10:02

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.

  • 1
    I would suggest something like tmux or screen too. – lucapette Jul 17 '12 at 8:56
  • Yes, indeed. But the asker insisted that it's a question about Vim itself. Tmux is great. Logged in on a remote server via SSH and using a well configured Vim within tmux/screen is a surprisingly enjoyable experience. Perfect for getting in the zone and staying there. – romainl Jul 17 '12 at 9:13
  • @romainl thank you for your awesome answer. I used gVim and I falsely assumed CLI vim also cannot display color... With some trials I found color is correctly displayed in my CLI vim. – CMinus Jul 17 '12 at 17:17

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


You can make a function in .bashrc:

function ls { /bin/ls --color=always; }
export -f ls
  • Sorry for the typo, but I'm not asking how to display color with "ls" command -- I'm curious about how to retain the color when executing the external commands with vim. I just used "ls" as an example. – CMinus Jul 17 '12 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.