Change syntax color in vim? - vim

I have syntax highlighting on, but comments are set to dark blue. This hard for me to read against a black terminal. How do I change it so that the comments are colored green instead?

Probably you just need to tell vim that you have a dark background:
:set background=dark
This should change the highlighting to something better readable.

Take a look at syncolor.vim. You'll find it in /usr/share/vim/vim{version}/syntax/.
Excerpt:
" There are two sets of defaults: for a dark and a light background.
if &background == "dark"
SynColor Comment term=bold cterm=NONE ctermfg=Cyan ctermbg=NONE gui=NONE guifg=#80a0ff guibg=NONE
SynColor Constant term=underline cterm=NONE ctermfg=Magenta ctermbg=NONE gui=NONE guifg=#ffa0a0 guibg=NONE
SynColor Special term=bold cterm=NONE ctermfg=LightRed ctermbg=NONE gui=NONE guifg=Orange guibg=NONE
So the first SynColor line looks of interest. I confess I don't know if you can override this, as opposed to changing this file.

If you want to change the color of a comment without changing the background, you can use the highlight command. Vim documentation on :highlight
For example, :hi Comment term=bold ctermfg=Cyan guifg=#80a0ff gui=bold

$VIMRUNTIME/colors/README.txt (on my system, /usr/share/vim/vim72/colors)

You can set colorsheme to desert. Default in e.g. Ubuntu 16.04

best way is to change colorscheme to another (lighter) one:
in navigation mode type:
:colorscheme space Ctl+D
and then type the scheme name Enter

For the googler's out there.
https://vimdoc.sourceforge.net/htmldoc/syntax.html
You can change the highlighting per syntax file, like in javascript.vim or python.vim syntax files.
For example changing a 'Comment' to be the color green. You would add this line somewhere inside of the respective syntax file.
hi Comment term=NONE cterm=NONE ctermfg=GREEN ctermbg=NONE gui=NONE guifg=NONE guibg=NONE
and you can do this for others like 'String'
hi String term=NONE cterm=NONE ctermfg=MAGENTA ctermbg=NONE gui=NONE guifg=NONE guibg=NONE

Related

How do I allow syntax highlighting to override the color scheme in Vim?

I am currently using the following lines from this answer in my .vimrc to fix my colorscheme when using vimdiff:
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
This works great for ordinary text file diffs. Unfortunately, when this is enabled and I diff two java files, the lines that are added (in the diff) lose their syntax highlighting.
Is there a way to make syntax highlighting run after the lines above, so that I can git reasonable diff highlighting while preserving syntax highlighting?

Get rid of the underline in Vim's fold name

This is my setting for Vim's folding:
hi Folded term=bold ctermfg=White
How do I get rid of the underline?
For attributes that you don't specify, the :hi command will keep the previous one. So if your colorscheme includes cterm=underline, you need to configure this:
hi Folded term=bold cterm=NONE ctermfg=White

Linux VIM : Omnicppcomplete + supertab use bash color theme

I use vim with omnicppcomplete and supertab for programming. The dropdown window, which shows possible completions is like pink. How can i change the color for example to my personal bash color theme?
Open your colorscheme.
Find the lines that start with hi Pmenu*.
Edit them to your liking.
If there's no such line in your colorscheme, add the lines below and change the colors to what you want:
hi Pmenu cterm=none ctermfg=White ctermbg=Black
hi PmenuSel cterm=none ctermfg=Black ctermbg=DarkGreen
hi PmenuSbar cterm=none ctermfg=none ctermbg=Green
hi PmenuThumb cterm=none ctermfg=DarkGreen ctermbg=DarkGreen
See :help :highlight for more.

MatchParen and cursorcolumn conflict

Vim is not showing the matching brackets on the same column when I do in _vimrc
:set cursorline
:set cursorcolumn
Actually I have in my _vimrc
:set cursorline
:set cursorcolumn
:highlight CursorLine term=underline guibg=#fffcd0 cterm=underline
:highlight CursorColumn term=underline guibg=#e1ffd5 cterm=underline
Then the matching bracket on the same column does not highlight.
I tried below playing with guibg and guifg with Black and Cyan and gui=inverse as:
:highlight MatchParen guibg=somecolors guifg=othercolor gui=inverse
But nothing works.
I need the highlighted current column as #e1ffd5 and current line as #fffcd0, and
the matching brackets highlighted.
I need the both. How can I?
Normally if you do not turn on cursorline and cursorcolumn then there will be no problem, vim will show every matching paren normally, like:
image01.
All the problems will take place if you turn on cursorline and cursorcolumn. The matching paren highlight on the same column at the other end will be vanished, like:
image02.
Finally I tried
:highlight MatchParen guibg=Black guifg=Cyan gui=inverse
But this also is not very perfect. Paren on the other side will fade into white, which I never want.
I want everything perfectly, better saying a mixture of picture 1 and 2 both.
I tried but I could not.
Setting ctermfg and/or guifg to NONE gets you what you want.
hi CursorColumn cterm=NONE ctermbg=236 ctermfg=NONE gui=NONE guibg=#2d2d2d guifg=NONE
hi CursorLine cterm=NONE ctermbg=236 ctermfg=NONE gui=NONE guibg=#2d2d2d guifg=NONE
With the cterm settings I found the following.
First I found that the following command made the matching paren disappear.
:hi MatchParen cterm=NONE ctermfg=black ctermbg=white
While my cursor was on these pren, I switched over to next vertical split, and saw that the colors of the matching peren were reversed.
That led me to the solution with the following command.
:hi MatchParen cterm=reverse
or
:hi MatchParen cterm=reverse ctermfg=<your color> ctermbg=<your color>
I think the color you are looking for is
(steelblue and black) or (black and steelblue)
My setting and I didn't change :hi cursorcolumn.
:hi MatchParen cterm=reverse ctermfg=NONE ctermbg=NONE

How to change the color of the selected code (Vim scheme)?

How do I change the color of the selected code in Vim?
There are three selection modes, Visual Line mode or Visual Block mode, and selecting with the mouse).
hi CursorLine guibg=#DDDDDD gui=none
hi CursorColumn guibg=#EEEEEE gui=none
hi MatchParen guifg=#f6f3e8 guibg=#857b6f gui=none
hi Pmenu guifg=#f6f3e8 guibg=#DDDDDD gui=none
hi PmenuSel guifg=#000000 guibg=#DDDDDD gui=none
endif
" General colors
hi Cursor guifg=NONE guibg=#656565 gui=none
hi Normal guifg=#000000 guibg=#FFFFFF gui=none
hi NonText guifg=#808080 guibg=#FFFFFF gui=none
hi LineNr guifg=#857b6f guibg=#FFFFFF gui=none
hi StatusLine guifg=#000000 guibg=#FFFFFF gui=none
hi StatusLineNC guifg=#857b6f guibg=#FFFFFF gui=none
hi VertSplit guifg=#444444 guibg=#FFFFFF gui=none
hi Folded guibg=#AAAAAA guifg=#FFFFFF gui=none
hi Title guifg=#000000 guibg=NONE gui=none
hi Visual guifg=#000000 guibg=#FFFFFF gui=none
hi SpecialKey guifg=#808080 guibg=#FFFFFF gui=none
How do I know which line it is?
Selection color for gvim is set by the following line:
hi Visual guifg=#000000 guibg=#FFFFFF gui=none
You can use named color values instead of the #nnnnnn RGB codes. Your existing line is set for black foreground and white background, just as you observed.
For example, if you want a light blue background with white foreground:
hi Visual guifg=White guibg=LightBlue gui=none
Be sure the color file you are editing is in the vim7x/colors directory so both vim and gvim can find it. Its exact location can vary a bit depending on your OS platform.
How to set the color of the selected code in vi?
I'm using VIM 7.3 on Ubuntu and this does it for me within the editor:
:syntax on
:hi Visual term=reverse cterm=reverse guibg=Grey
I'm using a colorscheme defined in the /home/youruser/.vim/colors/mycolorscheme.vim file. I set the command there and the changes take effect when vim starts.
syntax on
hi Visual term=reverse cterm=reverse guibg=Grey
mu color scheme is molokai, and I found that this configuration is the best for me:
highlight Visual cterm=bold ctermbg=Blue ctermfg=NONE
check out my vimrc #https://github.com/reubinoff/myVimrc
I just change my color scheme file (~/.vim/colors/solarized.vim), and set 'Visual' to the same value as 'CursorLine'.
I like the style of CursorLine as it is transparent and keep the selected elements's syntax highlight color.
Replace the line that contains exe "hi! Visual" with the following line:
exe "hi! Visual" .s:fmt_uopt .s:fg_none .s:bg_base02 .s:sp_base1
or:
:highlight Visual cterm=NONE ctermbg=0 ctermfg=NONE guibg=Grey40
Like so:
My highlight
:hi Visual cterm=none ctermbg=darkgrey ctermfg=cyan
More xterm colors: https://github.com/guns/xterm-color-table.vim

Resources