Có rất nhiều tài liệu trong vim để quản lý trình bày màu. Đây là phần tôi nghĩ sẽ hữu ích nhất cho bạn:
17. Color xterms xterm-color color-xterm
Most color xterms have only eight colors. If you don't get colors with the
default setup, it should work with these lines in your .vimrc:
:if &term =~ "xterm"
: if has("terminfo")
: set t_Co=8
: set t_Sf=<Esc>[3%p1%dm
: set t_Sb=<Esc>[4%p1%dm
: else
: set t_Co=8
: set t_Sf=<Esc>[3%dm
: set t_Sb=<Esc>[4%dm
: endif
:endif
[<Esc> is a real escape, type CTRL-V <Esc>]
You might want to change the first "if" to match the name of your terminal,
e.g. "dtterm" instead of "xterm".
Note: Do these settings BEFORE doing ":syntax on". Otherwise the colors may
be wrong.
xiterm rxvt
The above settings have been mentioned to work for xiterm and rxvt too.
But for using 16 colors in an rxvt these should work with terminfo:
:set t_AB=<Esc>[%?%p1%{8}%<%t25;%p1%{40}%+%e5;%p1%{32}%+%;%dm
:set t_AF=<Esc>[%?%p1%{8}%<%t22;%p1%{30}%+%e1;%p1%{22}%+%;%dm
colortest.vim
To test your color setup, a file has been included in the Vim distribution.
To use it, execute this command:
:runtime syntax/colortest.vim
Some versions of xterm (and other terminals, like the Linux console) can
output lighter foreground colors, even though the number of colors is defined
at 8. Therefore Vim sets the "cterm=bold" attribute for light foreground
colors, when 't_Co' is 8.
xfree-xterm
To get 16 colors or more, get the newest xterm version (which should be
included with XFree86 3.3 and later). You can also find the latest version
at:
http://invisible-island.net/xterm/xterm.html
Here is a good way to configure it. This uses 88 colors and enables the
termcap-query feature, which allows Vim to ask the xterm how many colors it
supports.
./configure --disable-bold-color --enable-88-color --enable-tcap-query
If you only get 8 colors, check the xterm compilation settings.
(Also see UTF8-xterm for using this xterm with UTF-8 character encoding).
This xterm should work with these lines in your .vimrc (for 16 colors):
:if has("terminfo")
: set t_Co=16
: set t_AB=<Esc>[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm
: set t_AF=<Esc>[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm
:else
: set t_Co=16
: set t_Sf=<Esc>[3%dm
: set t_Sb=<Esc>[4%dm
:endif
[<Esc> is a real escape, type CTRL-V <Esc>]
Without +terminfo, Vim will recognize these settings, and automatically
translate cterm colors of 8 and above to "<Esc>[9%dm" and "<Esc>[10%dm".
Colors above 16 are also translated automatically.
For 256 colors this has been reported to work:
:set t_AB=<Esc>[48;5;%dm
:set t_AF=<Esc>[38;5;%dm
Or just set the TERM environment variable to "xterm-color" or "xterm-16color"
and try if that works.
You probably want to use these X resources (in your ~/.Xdefaults file):
XTerm*color0: #000000
XTerm*color1: #c00000
XTerm*color2: #008000
XTerm*color3: #808000
XTerm*color4: #0000c0
XTerm*color5: #c000c0
XTerm*color6: #008080
XTerm*color7: #c0c0c0
XTerm*color8: #808080
XTerm*color9: #ff6060
XTerm*color10: #00ff00
XTerm*color11: #ffff00
XTerm*color12: #8080ff
XTerm*color13: #ff40ff
XTerm*color14: #00ffff
XTerm*color15: #ffffff
Xterm*cursorColor: Black
[Note: The cursorColor is required to work around a bug, which changes the
cursor color to the color of the last drawn text. This has been fixed by a
newer version of xterm, but not everybody is using it yet.]
To get these right away, reload the .Xdefaults file to the X Option database
Manager (you only need to do this when you just changed the .Xdefaults file):
xrdb -merge ~/.Xdefaults