Inverted colors in status line. Why? - vim

I use gvim 7.4 on Windows, clean install, no plugins. Can anybody explain, why this:
highlight statusline guifg=red guibg=green
will show me green text on red background.
But this one:
highlight statusline gui=NONE guifg=red guibg=green
will show red text on green background?
(The actual goal was to change the text in statusline from bold to normal. For this task, I added gui=NONE and then, see this strange behaviour).
Edit
(As my answer to Kent's comment)
Here is my complete _vimrc. There are only two lines on code:
set laststatus=2
highlight statusline gui=NONE guifg=red guibg=green
Also tried:
hi gives the same effect as highlight
StatusLine gives the same effect as statusline

To check how was a hi-group defined, in vim use: hi GroupName, that's why I keep asking OP and Carpetsmoker to provide their cmd output.
After vim has been compiled and installed, some default HL-Groups have been already defined.
From time to time people asked about the default color scheme. And want to extend the "default" color scheme. The location is easy to find, on a linux box, e.g. it locates at /usr/share/vim/vim74/colors/default.vim, different distributions could have different paths.
However if we open the default.vim, we will see a rather simple vim file. No any HL definition. Because they were in vim source codes as default defined.
Regarding the StatusLine group, it was defined in syntax.c file:
https://github.com/vim/vim/blob/8bc189e81aa98ba4aebb03a9dc9527a210fce816/src/syntax.c#L6784
We can see that the reverse is in StatusLine and StatusLineNC groups.
To get rid of the reverse "feature", you have to overwrite the gui or cterm attribute.

This is because the default StatusLine is:
:hi StatusLine
StatusLine xxx term=bold,reverse cterm=bold,reverse gui=bold,reverse
Notice the reverse keyword in cterm and gui? That tells it to use reverse video.
This is also why the colours are what you expect if you use gui=NONE (or gui=bold).
hi gives the same effect as highlight
hi is just the abbreviated version of highlight.

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

VIM Background color issue

I want my vim background to be dark but as you can see it's not, its half black half grey, im using ubuntu 15.10 with latest vim version. How to fix this?
pic
If you want your background was of all the same colour, which is set in your colorsheme, you need to comment the line about highlighting nonText.
" highlight Normal ctermbg=black
" highlight nonText ctermbg=black
If you wish to override the settings in your colorscheme, just uncomment the line about highlighting Normal
highlight Normal ctermbg=black
highlight nonText ctermbg=black
If you want to see the current settings of the highlighting, you can use :highlight command.
Read more in help
:h highlight-groups

Vim command line color setting

Is there a way to set different colors for the command line color and the "Normal" text color in vim. When I use
:hi Normal guifg=orange
the command line and the normal text color become orange. I would like the command line at the bottom of the gui to be a different color however.
Nowadays NeoVim has the feature. MsgArea color group. e.g.
:hi MsgArea guifg=#03ff13
No, not that I know of.
Not without messing with Vim's source.
The command line is under Normal highlighting group.
This can be done with autocommands:
hi Normal=white guifg=white
au CmdLineEnter * hi Normal ctermfg=cyan guifg=cyan
au CmdLineLeave * hi Normal ctermfg=white guifg=white
Surprisingly to me, this only affects the CmdLine, not everything else.
I had expected all the normal text to change color immediately when entering the CmdLine. Without the CmdLineLeave, the change to the normal text everywhere happens, but only after getting out of the command line; which explains why it does what we want.
Note that I am using vim from a terminal, so I am using ctermfg instead of guifg; but I anticipate that it will work the same way with a gui version of vim.
You may also want to highlight the ModeMsg.
That can be done via new wincolor option that was introduced in Vim 8.2:
set wincolor=NormalAlt
autocmd WinEnter set wincolor=NormalAlt
hi Normal guifg=#CED1CF guibg=#000000 gui=NONE
hi NormalAlt guifg=#CED1CF guibg=#1B1D21 gui=NONE

Set vim bracket highlighting colors

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 )

Load different colorscheme when using vimdiff

How to load a different colorscheme when doing vimdiff.
I want this because the my current colorscheme does not show some diffs properly in vimdiff, For. eg some diff is shown with same fg/bg color. This makes it very hard to understand the diff. So every time i do a vimdiff i have to do :colorscheme some_other_scheme
Can this be done in .vimrc file?
I don't know why vim uses so many colors to highlight with, it doesn't really help you figure out what's going on.
I modified my colorscheme to only use one color to highlight (with another to show where theres a difference within a line) and it made all the difference.
Before
After
I did this by adding the following to the end of my colorscheme file (~/.vim/colors/mycolorscheme.vim).
highlight DiffAdd cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffText cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red
cterm - sets the style
ctermfg - set the text color
ctermbg - set the highlighting
DiffAdd - line was added
DiffDelete - line was removed
DiffChange - part of the line was changed (highlights the whole line)
DiffText - the exact part of the line that changed
I used this link as a reference for the color numbers.
Note: I didn't set the gui options because I use a different colorscheme for macvim/gvim
If you're calling vimdiff from the command-line, put the following in your .vimrc:
if &diff
colorscheme some_other_scheme
endif
If you're using vimdiff from within vim, you'd either have to override the commands you use to start/stop it (e.g. diffthis, diffoff) using :cnoreabbr (there's also a plugin) or use an autocommand:
au FilterWritePre * if &diff | colorscheme xyz | endif
FilterWritePre is called before filtering through an external program (the diff utility) and the &diff-option is set by vim when it's going into diff-mode (among others, see :help diff)
I'm not sure which autocommand to use to return to the original colorscheme though.
To answer my own question:
if &diff
colorscheme evening
endif
molokai:
github:
The two themes github and molokai are equally beautiful.
curl -fLo ~/.vim/colors/molokai.vim --create-dirs https://raw.githubusercontent.com/tomasr/molokai/master/colors/molokai.vim
curl -fLo ~/.vim/colors/github.vim --create-dirs https://raw.githubusercontent.com/endel/vim-github-colorscheme/master/colors/github.vim
Put the following code in your ~/.vimrc, you can choose github or molokai (a line starting with a " is a comment):
if &diff
" colorscheme github
colorscheme molokai
endif
I found the easiest way was to paste this one-liner into my ~/.vimrc file:
" Fix the difficult-to-read default setting for diff text highlighting. The
" bang (!) is required since we are overwriting the DiffText setting. The highlighting
" for "Todo" also looks nice (yellow) if you don't like the "MatchParen" colors.
highlight! link DiffText MatchParen
If you are encountering unreadable color schemes (not just ugly, but unreadable like white text on pink background), an easy fix may be to use 16 colors instead of 256 colors. Then you don't have to mess with the color schemes.
The reason is that the default vimdiff color scheme assigns DiffChange bg as "LightMagenta", which gets mapped to a very light pink in 256 colors. That is unreadable with white text. With 16 colors, the "LightMagenta" is mapped to a bold magenta, which white text shows up much better on.
You can give a quick test by doing something like this:
vimdiff <file1> <file2>
:set t_Co? " print current setting (256 by default)
:highlight " print highlighting scheme
:set t_Co=16 " set to 16 colors
:highlight " print highlighting scheme
256-color screenshot
16-color screenshot
As you can see, the 16 colors is much more readable, without changing the color scheme.
To make this permanent, you can add set t_Co=16 to your .vimrc
For people that use the very excellent Solarized theme there's an option that turns on high visibility for diff mode:
" ~/vim.rc
" Set high visibility for diff mode
let g:solarized_diffmode="high"
"normal"
"high"
"low"
my current colorscheme does not show some diffs properly in vimdiff, For. eg some diff is shown with same fg/bg color
Actually, I've found that the main culprit for same fg/bg color is because of conflict between code syntax highlighting and diff colorscheme. You can try to change the diff colorscheme, but it may be a game of whack-a-mole when you open different file types (with different code syntax highlighting).
A sure solution is to disable the syntax highlighting in vimdiff. You can either type:
:syntax off
Or if you want to automatically do this every time, then add this to the end of your ~/.vimrc:
if &diff
syntax off
endif
Another approach is to fix that color scheme.
As far as I know, there are usually four highlight groups relative to diff'ing: DiffAdd, DiffChange, DiffDelete, and DiffText. If you don't want to be bothered about the syntax or tweaking the colors to your liking, you could probably copy your default color scheme under another name to ~/.vim/colors (create the directory if it doesn't exist) and copy paste the corresponding :hi commands from your alternative color scheme to the end of your new custom color scheme, optionnally commenting out any other diff-related statements therein.
And if the result is an obvious improvement, send an email to the maintainer of your color scheme with your changes and ask him to look into the problem. There's a good chance that he will thank you for your interest and that he will fix his color scheme so that other users will also benefit..
/etc/vim/vimrc or ~/.vimrc:
If using a dark background within the editing area and syntax highlighting turn on this option as well set background=dark
To expand on #dean and some other answers here, add this to your .vimrc:
if &diff
" colorscheme evening
highlight DiffAdd cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffText cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red
endif
I use the following when using vimdiff from within vim:
au BufEnter,BufNew * if &diff | syntax off | else | syntax on | endif
The part with else statement is important because that's how you go back to your previous config after you are done with diff'ing. So you can replace syntax off and syntax on with respective colorscheme commands. This autocmd handles changing a setting and reverting it when quitting vimdiff (I use Gdiff to be precise).
None of the solutions were working for me. When I used the if &diff check, it was only working if I resourced my config after opening the diff (:Gdiff from fugitive.vim plugin). It wasn't opening automatically. Moreover, after quitting the diff pane, I had to resource to get back my original color scheme.
Hence, I ended up creating custom maps that would activate the required color scheme.
map ,m :colorscheme molokai<CR>
map ,c :colorscheme PaperColor<CR>
map ,g :colorscheme gruvbox<CR>
So far, this is the most promising solution I found, even though it's a bit of a hack and I would've liked it if the color scheme changed automatically.
However, this way, I can apply any color scheme quickly at my leisure irrespective of whether I am in a diff window or not.
The slate colorscheme which comes standard with most vim installations works fine for me. FWIW, I work with a dark background. Thus I simply add the following to my .vimrc:
if &diff
colorscheme slate
endif

Resources