Set vim bracket highlighting colors - vim

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:
and when the cursor is to the immediate-right of the brace:
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.

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 )

Related

In vim, how to highlight a line while keeping syntax coloring?

In vim, I want to:
highlight a single line (e.g. :hi CursorLine ctermbg=black)
AND
maintain syntax highlighting
AND
not set up any custom color themes or similar
(note: adding a few lines to .vimrc is fine)
I've tried setting via :hi CursorLine ctermbg=black, but this results in changing the cursor highlight color but not maintaining syntax coloring.
not highlighted, and has syntax coloring:
highlighted, but loses syntax coloring:
in above example, I would want the string word to stay purple, if word stay yellow, etc., even though line is highlighted.
I also tried toggling :syntax off :syntax on, and not surprisingly this had no effect.
This question (Syntax highlighting in vim) seems similar to what I'm asking, but it's not because 1) I don't want to change the background, 2) I don't want to change theme, 3) it seems like OP here was having trouble with existing syntax color scheme and just wanted to be able to see things.
This question (Custom syntax coloring vim) seems similar to what I'm asking, but it's not because 1) I don't want to change existing syntax coloring, I want to keep it, 2) I don't want to add arbitrary syntax highlighting, I just want CursorLine to be highlighted while also maintaining syntax coloring.
I got my desired behavior by running :hi CursorLine ctermbg=black term=none cterm=none.
And while out of scope of my original question, running :set cursorline is also needed for the line highlighting to be displayed.
This seemed to work for me ...
:hi CursorLine cterm=NONE guifg=NONE

How to stop vim colorscheme using wrong colours for visible tab characters

In my vim setup, I have invisible char show up with set list. I am using solarized dark theme, but changing theme I still get the same problem and sometimes a lot worse!
The tab characters are showing up a different colour from the background.
How do I stop this behaviour as the effect is overpowering when it should be subtle!
:help 'listchars' explains:
The "NonText" highlighting will be used for "eol", "extends" and
"precedes". "SpecialKey" for "nbsp", "space", "tab" and "trail".
|hl-NonText| |hl-SpecialKey|
So, what's annoying you is the background color of the SpecialKey highlight group. (Unless you use some special indent-highlight plugin, but you would have told us, right?)
To fix this, just redefine the highlight group, after a :colorscheme command in your ~/.vimrc. For example, clear the background color:
:highlight SpecialKey ctermbg=NONE guibg=NONE

In Vim can you stop the color change of white space characters with 'set cursorline' on?

In this Vim screenshot you can see that when moving the cursor over a line it changes the normal color of the whitespace characters (shown on the left) from grey to black. Can I stop this and leave them showing grey always, regardless of cursor position?
I've tried setting these in the colour scheme but no luck:
hi SpecialKey guibg=bg guifg=#CCCCCC gui=none
hi NonText guibg=bg guifg=#CCCCCC gui=none
You can use :match to highlight the tabs.
:match NonText '^\s\+'
That seems to override the cursor line. It would be better of course to use matchadd() but it seems to be overriden by the cursor line. There might be a way to make it work
Following lines in .vimrc fixed the problem for me.
au VimEnter * call matchadd('SpecialKey', '^\s\+', -1)
au VimEnter * call matchadd('SpecialKey', '\s\+$', -1)
It overrides other styles application for tabs and trailing spaces inside a cursor line.
Yes you can. From :help listchars (at the end):
The "NonText" highlighting will be used for "eol", "extends" and
"precedes". "SpecialKey" for "nbsp", "tab" and "trail".
With this knowledge you can modify your color scheme accordingly or add a call to highlight in your vimrc.
I believe you have 'cursorline' set. The CursorLine highlight group defines the highlights for the same. Either you set nocursorline, (which can speed line movements) or change the CursorLine highlight groups fg colors.

How do you change the background color of the empty tab space in vim?

In vim, when you create a new tab, the tab bar appears at the top of the screen. On the left are all your tabs, on the far right is an "X" for closing the tabs. In between, there is "empty" space, that on my screen appears white.
I'll admit, I'm very picky about how my terminal looks, and this bright white bar at the top of the screen is distracting. Is it possible to change this color to black, or maybe even gray?
TLDR;
For a black tab bar (color 0)
:hi TabLineFill term=bold cterm=bold ctermbg=0
Explanation
Use vim's highlight command to set the attributes you want on the TabLineFill group.
This command will show you a list of all the current groups and their highlight attributes.
:hi
Find TabLineFill, and next to it you will see a preview of how your "tab line" will appear. Also note the attributes on this line.
In order for the color you want to be displayed, the attribute representing your terminal needs to be set to "bold". The two options are "term" and "cterm". If your using vim in a color terminal, then cterm will apply, otherwise term will apply. Set these attributes to bold like this:
:hi TabLineFill term=bold cterm=bold
The attribute "ctermbg" may or may not appear on the TabLineFill line, but it is used to define the color of the terminal background. See the list of cterm-color options by typing:
:help cterm-colors
Choose a color (for unobtrusive, I recommend 0, which is Black), then set the ctermbg attribute to the code for that color:
:hi TabLineFill ctermbg=0
This can all be combined into one single command:
:hi TabLineFill term=bold cterm=bold ctermbg=0
Try the following: (you can put that in your .vimrc)
:hi TabLineFill ctermbg=100
you can play with the colors and choose one that you like.
If you came here looking to change colours of the tab character, you want this:
:highlight SpecialKey guifg=<color> ctermfg=<color>
Since this is the first google result for "vim tab background color":
TabLineFill's ctermbg doesn't do anything for me. Set ctermfg=N where N is the desired background color. Don't set ctermbg, and definitely don't set ctermbg=ctermfg as this creates a white background.
That color is controlled by the current colorscheme. You can use :colorscheme to change schemes and find one you like (that has a better color for that area). You can see some sample schemes here (albeit without a tab bar shown).
vi, set the background color of tabs:
Manually in vim at the vim command terminal:
:syn match Tab "\t"
:hi def Tab ctermbg=darkgreen guibg=#003000
I used the following commands in the vim syntax file to make the changes permanent: (they didn't work in the ~/.vimrc nor the colors/monokai.vim colorscheme files)
syn match Tab "\t"
hi def Tab ctermbg=darkgreen guibg=#003000
I got these results:
Alternatively, There is a syntax highlighting scheme called: "whitespace.vim" that manipulates these background colors. It should just work and you can see it in action by using the command:
:set syntax=whitespace
It has custom colors for the various types of whitespace, you can follow that and see how it works to copy it.

CursorLine highlight in ViM, highlight only line number and spaces/tabs on beginning /end of the line

I use ViM's :highlight CursorLine to change bg color on the current line. But sometimes the text not readable.
I would like a highlight that could only change the background color for the whole line except the text (counting the spaces/tabs in between chars as text).
Is it doable? If yes, how?
As for as I know, there might be no direct support of setting how the cursorline is highlighted.
But, I've got a trick for doing what you want. That is, after we highlight the cursorline, we can change the color settings of heading/trailing spaces in a line as current "background" and "foreground".
:match NoHighLight /^\s\+|\s\+$/
:highlight NoHighLight guibg=background guifg=foreground
A obvious drawback is the part from "the end of the line" to "the boundary of the vim window" will still be painted as the color of cursorline's setting. If it is ugly for you, you can just change the highlight setting of cursorline by only setting its guifg, like:
:highlight CursorLine guifg=red guibg=background
Maybe there are other neat solutions existed, but that is what I can come up with now. :)
Hope that helps a bit.
I have found a solution -
With regard to #Zhaojun's answer: it's not what I wanted (also /^\s\+|\s\+$/ doesn't do much, maybe it should be /^\s\+\|\s\+$/)
The solution I found is (just example color for elflord color scheme)
:highlight CursorLine gui=none guibg=grey10
:set CursorLine
:highlight NoHighLight guibg=background
:match NoHighLight /\S\+\(\s\+\|$\)/
it's however not working well for trailing spaces at he end of line, but I usually delete them
to make them visible I use the following
:highlight EndSpaces guibg=green
:match EndSpaces /\s\+$/

Resources