1

One of the reasons i prefer to run Vim from a terminal instead of running gVim is that the output of external gets cluttered up by escape sequences each time I execute commands like ls and grep that I have aliased to colorize the output in my .bashrc.

When executing :!ls I get output that looks like this:

[0m[01;34mDesktop[0m    [01;34mDocuments[0m    [01;34mDownloads[0m
[01;34mGit[0m    [01;34mMail[0m    [01;34mMusic[0m
[01;34mPictures[0m    [01;34mProgramming[0m
[01;34mPublic[0m    [01;34mSoftware[0m    [01;34mTemplates[0m    todo.txt    [01;34mVideos0m

Screenshot here:enter image description here

Try executing :!vi in gVim and your entire screen will explode.

Is there a solution to this problem? Is it possible to make gVim discard escape sequences when printing the output of an external command?

2

You should take a look at the manual of those commands: they may allow you to define when to show colors or not.

ls, for example, has the --color=auto option that makes it show colors only when possible.

2

The issue is that gVim doesn't emulate a full terminal, in this particular case, it doesn't recognize colour codes.

This is simply something you can't do in gVim, unless you spawn a new terminal with :!xterm -e 'ls && read', use :!/bin/ls to prevent loading your ls alias which adds colours, or filter the colors with something like :!ls | sed 's|\x1b\[[;0-9]*m||g' (I have that sed command as a shell alias).

See also: What additional features do gVim and/or MacVim offer compared to Vim inside a terminal emulator?.

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.