I am using dracula theme for vim and am not able to get the number pane, that is, the side panel which contains the line numbers, to be displayed in a sort of translucent manner. The preview image shows that it's possible.
How the terminal should look like
(source: draculatheme.com)
How it actually looks
To fix this issue, I think I need to configure some attributes accordingly, but being a beginner, I don't know which ones, therefore any help and guidance would be appreciated.
As a reference, these are my dotvim files.
The background of the line numbers column is set in the colorscheme to NONE for color terminals and #282a36 for GUIs:
hi LineNr ctermfg=60 ctermbg=NONE cterm=NONE guifg=#6272a4 guibg=#282a36 gui=NONE
From there you have three options:
Enable the 'termguicolors' option so that Vim uses the gui* attributes instead of the cterm* attributes.
This is how the screenshot was taken but it will only work in select terminal emulators.
See :help 'termguicolors'.
Edit the colorscheme directly:
hi LineNr ctermfg=60 ctermbg=242 cterm=NONE guifg=#6272a4 guibg=#282a36 gui=NONE
I've chosen 242 arbitrarily but you can choose whatever color you want in this chart
Override your colorscheme in your vimrc:
function! MyHighlights() abort
hi LineNr ctermfg=60 ctermbg=242 cterm=NONE guifg=#6272a4 guibg=#282a36 gui=NONE
endfunction
augroup MyColors
autocmd!
autocmd ColorScheme * call MyHighlights()
augroup END
colorscheme dracula
I believe it's possible to get an underline under the current line, rather than a highlight.
This adds the highlight in my .vimrc:
set cursorline
This is what I've tried adding to get an underline:
:highlight CursorLine gui=underline cterm=underline
But it appears to make no difference.
I'm using vim 7.4.629 on Centos 6.7 through putty, if that helps.
try :hi clear CursorLine to clear the current cusorline hl, then :hi CursorLine gui=underline cterm=underline
The color of underline is same as your ctermfg or guifg. You can either live with your "colorful" underline, or add cterm/guifg to make the underlined text and the underline same color.
:set cursorline
was the best solution for me, you can combine it with removing the cursorLine as the answer above mentions
For me it works best to highlight the cursor line only in Insert mode. To do so, I use the action snippet to activate cursor underlining (full line) whenever Insert mode is activated and later deactivating it upon leaving the mode.
au InsertEnter * set cul
au InsertLeave * set nocul
With :set cursorline and :set list, the characters in the NonText and SpecialKey highlight groups (for example, $ at the end of each line, and ^M produced by Ctrl+VEnter) lose their highlighting when the cursor is on the same line, reverting to the Normal highlight group like any other bland text. This is very confusing and ugly and bad.
These are the relevant highlights in my config:
:hi Conceal term=reverse cterm=none ctermfg=237 ctermbg=none
:hi CursorLine term=underline cterm=none ctermfg=none ctermbg=235
:hi NonText term=reverse cterm=none ctermfg=237 ctermbg=none
:hi Normal term=none cterm=none ctermfg=252 ctermbg=234
:hi SpecialKey term=reverse cterm=none ctermfg=14 ctermbg=23
The problem persists no matter my highlight configuration (including no configuration at all). I know that some highlight groups just always trump others, but syntax highlighting and highlighting from other groups (Conceal, for example) remains intact; is there a way to make NonText and SpecialKey retain their highlight?
As far as I'm aware, no. Bram Moolenaar has said the following on this matter:
There is no solution. [...] The cursorline highlighting needs to overrule the syntax highlighting, otherwise it would disappear in several situations, esp. if the syntax highlighting uses background highlighting.
If you only want to highlight the line number that the cursor is on you can use
hi CursorLineNr term=underline cterm=none ctermfg=none ctermbg=235
hi CursorLine term=NONE cterm=NONE
(vim8)
Is there a way to highlight only the current line number (in the left hand coloumn) in vim, without highlighting the background of the current line? Ideally, I would Like to make the current line number bold.
There are two groups that determine highlighting of line displayed when &cursorline option is active: CursorLine and CursorLineNR. First is used to highlight the whole line, second for the line number. So to achieve what you want you must
Clear the highlighting of CursorLine: just hi clear CursorLine after any :colorscheme and set background= call.
hi clear CursorLine
augroup CLClear
autocmd! ColorScheme * hi clear CursorLine
augroup END
Set the highlighting of CursorLineNR if it is not set in your colorscheme:
hi CursorLineNR cterm=bold
augroup CLNRSet
autocmd! ColorScheme * hi CursorLineNR cterm=bold
augroup END
(better to check whether it is already set in the colorscheme, maybe it will look better in that case).
You can join both autocommands in one of course.
CursorLineNR has been added relatively recently around version 7.3.488.
You want to look at
:se cursorline
and perhaps even/also
:se cursorcolumn
This is what worked for me:
highlight CursorLine cterm=NONE ctermbg=NONE ctermfg=NONE guibg=NONE guifg=NONE
set cursorline
I'm just using this in my .vimrc after having set the color scheme. Of course you could also set a specific background color but setting all of them to NONE just highlights the line number (i.e. makes it brighter).
I guess you could just use :hi CursorLine cterm=NONE but I just wanted to make sure I'm making everything transparent (gvim included).
With CursorLineNR I was then able to set the foreground and background colors of the highlighted number.
I'm only writing this because for me it worked without any autocommands and it may be what most people require.
You can set cursorline to highlight only the numbers
'cursorlineopt' 'culopt' string (default: "number,line")
local to window
{not available when compiled without the +syntax
feature}
Comma separated list of settings for how 'cursorline' is displayed.
Valid values:
"line" Highlight the text line of the cursor with
CursorLine hl-CursorLine.
"screenline" Highlight only the screen line of the cursor with
CursorLine hl-CursorLine.
"number" Highlight the line number of the cursor with
CursorLineNr hl-CursorLineNr.
And to override your colorscheme use autocmd
So, the following works:
set cursorline
set cursorlineopt=number
autocmd ColorScheme * highlight CursorLineNr cterm=bold term=bold gui=bold
This worked for me to highlight the line number and not the rest of the line:
highlight CursorLineNr cterm=NONE ctermbg=15 ctermfg=8 gui=NONE guibg=#ffffff guifg=#d70000
The help for highlight-groups does not mention an exclusive "number of current line" syntax group, so the official answer might be no.
You may want to take a look in the cursorline option which highlights the entire line, if it helps.
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