104

I'm using :set showmatch to highlight the matching bracket or brace when the cursor is over one.

I'd like to change the highlight-color so that it's radically different from the cursor color, because I've got the situation shown in the screenshots.

When the cursor is over the second brace:

Cursor over the second brace

And when the cursor is to the immediate-right of the brace:

Cursor to the right

This uses my terminal color scheme, which is taken from Solarized. Unfortunately, it's a bit of a pain to see which highlight is the brace matching and which is the cursor, when the braces are close together.

Is there a Vim setting I can use to change the color of that to, say, the bold magenta ANSI? I'm not particularly interested in remapping my ANSI colors within the terminal or shell - I'd like a Vim-specific option, if it exists.

1
  • Yeah, this is kind of nuts. In Neovim, using the built-in colorschemes and lsp-zero, the matching highlight is identical to the cursor, and the cursor disappears briefly when you pass over a match, so it looks like the cursor just jumped to the matching bracket. Not sure yet exactly which piece of config is at fault, but It's maddening.
    – Sasgorilla
    Commented Feb 23, 2023 at 0:26

4 Answers 4

133

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
4
  • 13
    Thanks for this! If you use the GUI version, this works pretty well. "hi MatchParen guibg=NONE guifg=blue gui=bold" Commented Mar 23, 2013 at 16:24
  • 2
    Came across this answer while I was looking how to turn that feature (MatchParen) off, because I found the colors so irritating (molokai). Someone should fix the default...
    – JepZ
    Commented Nov 1, 2017 at 8:15
  • 3
    thnx! I'm using Neovim and in my case I had to set hi MatchParen guifg=lightblue guibg=darkblue. Commented Apr 17, 2020 at 16:59
  • Anyone have a Lua (Neovim) version of this?
    – Sasgorilla
    Commented Feb 23, 2023 at 0:21
8

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.

6

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

" 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 whichever you prefer from :!ls $VIMRUNTIME/colors).

5

Try :!ls $VIMRUNTIME/colors. These are default color schemes Vim supply.

Then change color scheme :colorscheme name, find the color scheme that you like and copy the color scheme: :!cp $VIMRUNTIME/colors/<name>.vim ~/.vim/colors/new_name.vim

Edit it and set with the color scheme command or better add colorscheme name to the .vimrc file. After changes to color file:colorscheme name, reload Vim's colors.

It's handy to use :vsp in create a vertical split in Vim. Edit the colors file in one half, and check changes in other. I used nye17's answer and added the hi MatchParen line to my color_file.vim. It works just fine.

Links:

1
  • Peter Mortensen, thank you for your help.
    – dobhareach
    Commented Mar 20, 2023 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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