设置 Vim 括号突出显示颜色

我使用 :set showmatch来突出显示光标大于1时匹配的括号或大括号。

我想改变高亮颜色,使其与光标颜色完全不同,因为我已经得到了截图中显示的情况。

当光标位于第二个大括号上时:
Cursor over the second brace

当光标在花括号的右边时:
Cursor to the right

这使用了我的终端配色方案,它取自 太阳能。不幸的是,当大括号靠得很近时,看看哪个突出显示是大括号匹配,哪个是光标有点痛苦。

有没有一个 vim设置,我可以用来改变的颜色,说,bold magenta ANSI?我对在终端或 shell 中重新映射我的 ANSI 颜色并不特别感兴趣——如果有的话,我想要一个特定于 vim的选项。

35051 次浏览

you can change the colors to, e.g., blue over green

hi MatchParen cterm=none ctermbg=green ctermfg=blue

just put it in your vimrc file.

basically, cterm determines the style, which can be none, underline or bold, while ctermbg and ctermfg are, as their names suggest, background and foreground colors, so change them as you see fit.

for your case, you may want

hi MatchParen cterm=bold ctermbg=none ctermfg=magenta

I'm using the vividchalk color scheme with macvim, and none of the various solutions I tried worked for me. But I searched the file:

~/.vim/colors/vividchalk.vim

for MatchParen and I found this line:

call s:hibg("MatchParen","#1100AA","DarkBlue",18)

I commented out that line, then I copied that line, and I changed it to:

 call s:hibg("MatchParen","#FF0000","Red",18)

which succeeded in highlighting the matching parenthesis in red, which is a LOT easier to see. I hope that helps someone else.

If you want to briefly jump to the opening bracket/paren/brace when you type the closing bracket/paren/brace, then adding:

set showmatch

to ~/.vimrc worked for me.

A very handy trick is setting the cursor on a bracket/paren/brace and then typing % to jump to the matching bracket/paren/brace. That is especially useful when the matching bracket/paren/brace has scrolled off the page. Typing % a second time will jump back to where you came from.

Try :!ls $VIMRUNTIME/colors these are default color schemes Vim supply. Than change color scheme :colorscheme name find color scheme that You like and copy color scheme :!cp $VIMRUNTIME/colors/<name>.vim ~/.vim/colors/new_name.vim edit it and set with color scheme command or better add colorscheme name to vimrc file. After changes to color file :colorscheme name reloads Vim's colors. It's handy :vsp vim, edit colors file in one half, check changes in other. I used nye17 answer and add hi MatchParen line to my color_file.vim it work's just fine.
Links:
Vim help
How to control colors
About Termianl colors

The colours that I use for vim highlighting, (from my ~/.vimrc):

" set sensible highlight matches that don't obscure the text
:highlight MatchParen cterm=underline ctermbg=black ctermfg=NONE
:highlight MatchParen gui=underline guibg=black guifg=NONE

NONE uses the character colour from the
:colourscheme ron (or which ever you prefer from :!ls $VIMRUNTIME/colors )