I am trying to change the spellcheck highlight group. So in the end of my .vimrc
I add the following code
highlight clear SpellBad
highlight SpellBad cterm=underline
when I open a new file, it is still showing the old syntax highlighting. But if I run the same commands inside vim manually after opened the file, it will work as expected.
Any idea what is going wrong here? Thanks!
Tweaks to a colorscheme have to happen after the colorscheme has been set. Usually, if you have the :colorscheme in your ~/.vimrc, and put the :highlight commands after it, that should work.
Your case seems to be different (which could be caused by a plugin manager affecting the loading order, or you might even have a dynamically changing colorscheme). To handle such eventualities, you can instead hook into the ColorScheme event:
autocmd ColorScheme * highlight clear SpellBad
autocmd ColorScheme * highlight SpellBad cterm=underline
I am having trouble on making the Vim Vertical Split Highlight disappear permanently.
When I use this command in Vim command line :hi VertSplit ctermbg=None the vertical split highlight disappears (as seen in Screen 'B'), but when I use the same command in the .vimrc.after (I am using janus for vim, as seen in screen 'A') the command does not work. I have tried many variations of the command with 'let','set', etc but no result, the Vertical Split stays.
Can someone please help and let me know what I doing wrong or what I am suppose to do? I want to remove the VerticalSplit highlight from my Vim.
Your .vimrc is executed sequentially, so probably this command is
being executed but then having its changes overwritten by another
command or plugin of yours. The solution would then be to move the
command to after these other changes happen. This may and may not work
depending on your setup (check :h startup for a list of what happens
at startup and in what order).
The best solution in my opinion is to use an auto command. These will
execute a command after an event, for example startup finished or
colorscheme changed. Add this to your .vimrc:
autocmd! ColorScheme * hi VertSplit ctermbg=none
Now, whenever the colorscheme is changed, this command will trigger for
any file (*). This will trigger as well by your initial colorscheme
set in your .vimrc.
Important! If your colorscheme set in your .vimrc is done before
your autocmd line, then of course nothing will be triggered (it won't
be capturing the event yet). In this case you have two options: first is
to obviously move the colorscheme set to after the autocmd. Second
option is add an additional event listener by changing the line to:
autocmd! VimEnter,ColorScheme * hi VertSplit ctermbg=none
Now this will be triggered both after Vim's startup process (after all
.vimrc stuff is done and loaded) and also whenever you change your
colorscheme. This way, you don't need to change your colorscheme files.
And you should never have to do that anyway. The point of .vimrc is to
keep all your configuration in one file. So this editor of course
provides options to make this happen.
On my system, I've aliased less to vim's less.sh macro (let's call it vless). For some reason, this macro doesn't fully import the line-highlighting settings in my .vimrc .
vless turns on highlighting, but uses underlining instead of bg+bold. In comparison, vim does exactly what I want. See pictures below. How do I fix this?
vimrc in vim:
Same file in (v)less:
Try using vimpager which is the successor to less.sh.
If you actually wanted to change the highlighting after less.sh did its own highlighting you could create the file ~/.vim/after/colors/<colorscheme_name>.vim with the following contents.
hi CursorLine term=bold cterm=bold ctermbg=Black
This should be sourced after less.sh does its own configuration.
When I open up a file in macvim it is like this http://imgur.com/a/3cLqB#0.
I have set ,V to :source ~/.vimrc<CR>.
After I have this file open, I press ,V, and the syntax highlighting changes to this http://imgur.com/a/3cLqB#1.
The difference is that (,),;,, become from blue, white, and ->,.,? become from blue, darker blue.
Why does that happen? This is my vimrc file https://gist.github.com/pvinis/4979592
--
Update: I found out that Valloric/vim-operator-highlight is the plugin that changes the colors. so the first picture is the correct picture.
I also found out, that as soon as i do :syntax on, the colors reset. Is there a way to check if syntax is already on?
Problem:
When reloading .vimrc, some highlight groups are messed up.
It depends on what plugins you have and what colorschemes you are using.
I've noticed that some highlight links were broken, and some highlight groups were cleared.
Affected highlight groups
In my particular setup I've noticed broken hi links or cleared groups on:
SignColumn
GitGutter (which uses SignColumn)
powerline-status (which uses status line)
Notice the affected areas after reloading:
(reloading means saving the modified file. Using :wa in this example)
Solution
Unfortunately the listed answers or any combination of options that I've tried does not preserve or reinstate the hi groups after reloading.
Running manually colorscheme <your-coloscheme> after reloading fixes everything, but when doing it with Vimscript it does not.
Hopefully someone will share a proper solution to this annoying small issue.
Ugly hack
Reloading vimrc:
On any change to my vim config files, I execute reload.vim:
.vimrc:
" .....
augroup reload_vimrc " {
autocmd!
autocmd BufWritePost ~/.vim/*.vim,~/.vim/vimrc source ~/.vim/reload.vim
augroup END " }
reload.vim: restores broken links and cleared groups
What we have to do is to reinstate the hi groups after sourcing vimrc.
To find the correct values for an affected area, e.g. for SignColumn, type:
:hi SignColumn, BEFORE any reloading has occurred.
The outcome is (where xxx is a preview):
You have to do this for every affected hi.
In the following snippet I initially fix SignColumn to match my solarized colorscheme.
Then I fix some GitGutter color issues:
e.g., GitGutterAdd is linked to GitGutterAddDefault which is preserved, but from GitGutterAddDefault to DiffAdd is broken, so I reinstall that one. And so on so forth.
reload.vim:
source ~/.vim/vimrc
hi SignColumn ctermfg=12 ctermbg=0 guifg=Cyan guibg=Grey
" GitGutterAdd -> GitGutterAddDefault (preserved)
hi link GitGutterAddDefault DiffAdd
" GitGutterChange -> GitGutterChangeDefault (preserved)
hi GitGutterChangeDefault ctermfg=3 ctermbg=0 guifg=#bbbb00
" GitGutterDelete -> GitGutterDeleteDefault (preserved)
hi GitGutterDeleteDefault ctermfg=1 ctermbg=0 guifg=#ff2222
" GitGutterChangeDelete -> GitGutterChangeDefault (preserved)
" (which we already fixed above)
" Powerline highlight groups
" (see this attached Gist for solution)
Everything works as it should:
Fixing powerline-status colors:
This one is a bit more tricky, but the principle is the same. All highlight groups of powerline start with Pl_. But some of them might not exist yet. For example, if you haven't entered visual mode yet, then the respective groups for visual mode won't be populated yet. So, enter insert, visual, and normal modes to populate the groups and then copy them. You can find them at the bottom of the output of the hl command. Then, paste them in your reload.vim and adapt them to be legit hl commands.
It may sound like a lot of work but it isn't.
Here's a gist with the full reload.vim, and some gifs to guide you through.
I had something very similar to this happening. I was able to solve it by making sure these were in the correct order:
syntax on
let g:solarized_termtrans=1
let g:solarized_termcolors=256
set background=dark
colorscheme solarized
I also used this for reloading
augroup reload_vimrc
autocmd!
autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup END
With those two I could do live updating of my vimrc without having to reload. I am using iTerm2 with Terminal vim. Hopefully this helps someone else out as I have spent quite a bit of time trying to get this live reloading working. Also make sure you have the newest versions of the solarized theme. I know it seems mundane to mention but it might make a difference.
I guess that the highlightings are defined / changed by some plugin. The re-execution of :colorscheme resets those definitions. The plugins would have to hook into the ColorScheme event with an :autocmd, but most don't.
To work around this, try wrapping the :colorscheme in a guard:
if ! exists('g:colors_name') || g:colors_name !=# 'Tomorrow-Night-Eighties'
colorscheme Tomorrow-Night-Eighties
endif
This works for me
"auto reload vimrc once changed
if has("autocmd")
autocmd! BufWritePost .vimrc source $MYVIMRC
" This fixes the color changes and things not working :D
autocmd! BufWritePost .vimrc filetype plugin indent on
endif
I have absolutely no idea why, (probably for the same reason that doing :source ~/.vimrc manually works) but for me replacing
autocmd BufWritePost *vimrc,*exrc :source %
with
autocmd BufWritePost *vimrc,*exrc :call feedkeys(":source %\<cr>")
fixed the problem.
autocmd BufWritePost *vimrc,*exrc :call feedkeys(":source %\<cr>")
Fixed it right away for me. Must be some weird issue with the ordering. I also have a keystroke to resource the file and this always works even when the autocmd was failing.
Most likely unrelated to your particular case, but I had a similar problem so I thought I'd share since it's the first StackOverflow result on Google.
My issue with reloading was in two phases: using the dark Solarized theme, reloading .vimrc would first change the colors slightly, then, reloading a second time, it would switch to the light Solarized theme.
The lines about colors in my .vimrc were:
set background="dark"
let g:solarize_termcolors=256
colorscheme solarized
The problem? The first line shouldn't have quotes:
set background=dark
I can now reload .vimrc without changing the colors. I'm not sure why it would work one time and work a different way after though. I realized that after commenting out everything but these lines as others have suggested.
set syntax enable after colorscheme
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