Last active
March 8, 2025 21:23
-
Star
(227)
You must be signed in to star a gist -
Fork
(17)
You must be signed in to fork a gist
Revisions
-
romainl revised this gist
Jun 26, 2021 . 1 changed file with 10 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ Your first reflex is probably to put those lines somewhere in your `vimrc`: highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f But it quickly appears that those lines have no effect if you source a colorscheme later in your `vimrc` so you move them below that `colorscheme` command: colorscheme foobar @@ -26,11 +26,11 @@ But it quickly appears that those lines have no effect if you source a colorsche which gives the desired outcome. Everything is fine. In principle. But you like to try new colorschemes, or you prefer to have different colorschemes for different filetypes or time of the day, and your overrides don't carry over when you change your colorscheme. This is because colorschemes usually reset all highlighting, including your own, when they are sourced. The solution is to override the desired highlights in an autocommand that's executed whenever any colorscheme is sourced: augroup MyColors autocmd! @@ -42,7 +42,7 @@ The solution is to override the desired highlights in an autocommand that's exec colorscheme foobar Note that the autocommand will have no effect on previously sourced colorschemes so it must be added *before* any colorscheme is sourced. Of course, we can go one step further and put all our highlights in a neat little function for maximum readability/managability/maintainability: @@ -78,6 +78,12 @@ This won't work if you have an autocommand like the following in your `vimrc` be autocmd BufWritePost $MYVIMRC source $MYVIMRC [...] By default, autocommands don't trigger other autocommands. In this classic example, an autocommand is set to `:source $MYVIMRC` automatically when you write it. The problem, here, is that you are very likely to have a line like this one somewhere in your `vimrc`: colorscheme whatever which, when it is executed as part of the re-sourcing of your vimrc, won't trigger the `ColorScheme` autocommand because of that "no nesting" rule. The solution is to add the `nested` keyword to that autocommand to allow other autocommands to be triggered by that event: [...] -
romainl revised this gist
May 21, 2021 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,6 +18,7 @@ Your first reflex is probably to put those lines somewhere in your `vimrc`: But it quickly appears that those lines have no effect if you source a colorscheme later in your `vimrc` so you move them below: colorscheme foobar highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f @@ -38,6 +39,7 @@ The solution is to override the desired highlights in an autocommand that's exec \ | highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f \ | highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f augroup END colorscheme foobar Note that the autocmd must be added *before* any colorscheme is sourced or it will have no effect. @@ -55,6 +57,7 @@ Of course, we can go one step further and put all our highlights in a neat littl autocmd! autocmd ColorScheme * call MyHighlights() augroup END colorscheme foobar ## But I only want that override for a single colorscheme @@ -63,6 +66,10 @@ The autocommands above use the glob `*` in order to override *any* colorscheme. autocommand ColorScheme foobar call MyHighlight() or, if you want to target several colorschemes: autocommand ColorScheme foobar,barbaz call MyHighlight() ## But this doesn't work when I "auto-source" my `vimrc` This won't work if you have an autocommand like the following in your `vimrc` because autocommands don't nest by default: @@ -77,6 +84,10 @@ The solution is to add the `nested` keyword to that autocommand to allow other a autocmd BufWritePost $MYVIMRC nested source $MYVIMRC [...] ## Reference For all things concerning autocommands, see the aptly named `:help autocommands`. For all things concerning syntax highlighting, see `:help syntax`. --- [My Vim-related gists](https://gist.github.com/romainl/4b9f139d2a8694612b924322de1025ce). -
romainl revised this gist
May 21, 2021 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ # The right way to override any highlighting if you don't want to edit the colorscheme file directly ## Generalities first Suppose you have weird taste and you *absolutely* want: * your visual selection to always have a green background and black foreground, @@ -55,11 +57,15 @@ Of course, we can go one step further and put all our highlights in a neat littl augroup END colorscheme foobar ## But I only want that override for a single colorscheme The autocommands above use the glob `*` in order to override *any* colorscheme. If, say… you really like the colorscheme `foobar` but you can't stand its `Visual` highlight, you will want your autocommand to target that colorscheme specifically. To this end, you can use the name of that colorscheme instead of `*`: autocommand ColorScheme foobar call MyHighlight() ## But this doesn't work when I "auto-source" my `vimrc` This won't work if you have an autocommand like the following in your `vimrc` because autocommands don't nest by default: [...] autocmd BufWritePost $MYVIMRC source $MYVIMRC -
romainl revised this gist
Apr 12, 2020 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # The right way to override any highlighting if you don't want to edit the colorscheme file directly Suppose you have weird taste and you *absolutely* want: * your visual selection to always have a green background and black foreground, @@ -68,3 +70,7 @@ The solution is to add the `nested` keyword to that autocommand to allow other a [...] autocmd BufWritePost $MYVIMRC nested source $MYVIMRC [...] --- [My Vim-related gists](https://gist.github.com/romainl/4b9f139d2a8694612b924322de1025ce). -
romainl revised this gist
Mar 16, 2020 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -53,6 +53,10 @@ Of course, we can go one step further and put all our highlights in a neat littl augroup END colorscheme foobar NOTE: The autocommands above use the glob `*` in order to override *any* colorscheme. If, say… you really like the colorscheme `foobar` but you can't stand its `Visual` highlight, you will want your autocommand to target that colorscheme specifically. To this end, you can use the name of that colorscheme instead of `*`: autocommand ColorScheme foobar call MyHighlight() NOTE: This won't work if you have an autocommand like the following in your `vimrc` because autocommands don't nest by default: [...] -
romainl revised this gist
Jan 14, 2018 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,18 +27,19 @@ This is because colorschemes usually reset all highlighting, including your own, The solution is to override the desired highlights in an autocommand that's executed whenever a colorscheme is sourced: augroup MyColors autocmd! autocmd ColorScheme * highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 \ | highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 \ | highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f \ | highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f augroup END colorscheme foobar Note that the autocmd must be added *before* any colorscheme is sourced or it will have no effect. Of course, we can go one step further and put all our highlights in a neat little function for maximum readability/managability/maintainability: function! MyHighlights() abort highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 @@ -50,6 +51,7 @@ And of course, we can go one step further and put all our highlights in a neat l autocmd! autocmd ColorScheme * call MyHighlights() augroup END colorscheme foobar NOTE: This won't work if you have an autocommand like the following in your `vimrc` because autocommands don't nest by default: -
romainl revised this gist
Jan 9, 2018 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,6 +27,7 @@ This is because colorschemes usually reset all highlighting, including your own, The solution is to override the desired highlights in an autocommand that's executed whenever a colorscheme is sourced: colorscheme foobar augroup MyColors autocmd! autocmd ColorScheme * highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 @@ -37,6 +38,7 @@ The solution is to override the desired highlights in an autocommand that's exec And of course, we can go one step further and put all our highlights in a neat little function for maximum readability/managability/maintainability: colorscheme foobar function! MyHighlights() abort highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 @@ -51,8 +53,12 @@ And of course, we can go one step further and put all our highlights in a neat l NOTE: This won't work if you have an autocommand like the following in your `vimrc` because autocommands don't nest by default: [...] autocmd BufWritePost $MYVIMRC source $MYVIMRC [...] The solution is to add the `nested` keyword to that autocommand to allow other autocommands to be triggered by that event: [...] autocmd BufWritePost $MYVIMRC nested source $MYVIMRC [...] -
romainl revised this gist
Nov 17, 2017 . No changes.There are no files selected for viewing
-
romainl revised this gist
Nov 5, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,9 +30,9 @@ The solution is to override the desired highlights in an autocommand that's exec augroup MyColors autocmd! autocmd ColorScheme * highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 \ | highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 \ | highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f \ | highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f augroup END And of course, we can go one step further and put all our highlights in a neat little function for maximum readability/managability/maintainability: -
romainl revised this gist
Nov 5, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,9 +30,9 @@ The solution is to override the desired highlights in an autocommand that's exec augroup MyColors autocmd! autocmd ColorScheme * highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 \ highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 \ highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f \ highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f augroup END And of course, we can go one step further and put all our highlights in a neat little function for maximum readability/managability/maintainability: -
romainl revised this gist
Nov 5, 2017 . 1 changed file with 11 additions and 11 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,25 +28,25 @@ This is because colorschemes usually reset all highlighting, including your own, The solution is to override the desired highlights in an autocommand that's executed whenever a colorscheme is sourced: augroup MyColors autocmd! autocmd ColorScheme * highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 \ highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 \ highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f \ highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f augroup END And of course, we can go one step further and put all our highlights in a neat little function for maximum readability/managability/maintainability: function! MyHighlights() abort highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f endfunction augroup MyColors autocmd! autocmd ColorScheme * call MyHighlights() augroup END NOTE: This won't work if you have an autocommand like the following in your `vimrc` because autocommands don't nest by default: -
romainl revised this gist
Nov 5, 2017 . 2 changed files with 58 additions and 67 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ Suppose you have weird taste and you *absolutely* want: * your visual selection to always have a green background and black foreground, * your active statusline to always have a white background and red foreground, * your very own deep blue background. Your first reflex is probably to put those lines somewhere in your `vimrc`: highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f But it quickly appears that those lines have no effect if you source a colorscheme later in your `vimrc` so you move them below: colorscheme foobar highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f which gives the desired outcome. Everything is fine. In principle. But you like to try new colorschemes, or you prefer to have different colorschemes for different filetypes or time of the day and your overrides don't carry over when you change your colorscheme. This is because colorschemes usually reset all highlighting, including your own, when they are sourced. The solution is to override the desired highlights in an autocommand that's executed whenever a colorscheme is sourced: augroup MyColors autocmd! autocmd ColorScheme * highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 \ highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 \ highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f \ highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f augroup END And of course, we can go one step further and put all our highlights in a neat little function for maximum readability/managability/maintainability: function! MyHighlights() abort highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f endfunction augroup MyColors autocmd! autocmd ColorScheme * call MyHighlights() augroup END NOTE: This won't work if you have an autocommand like the following in your `vimrc` because autocommands don't nest by default: autocmd BufWritePost $MYVIMRC source $MYVIMRC The solution is to add the `nested` keyword to that autocommand to allow other autocommands to be triggered by that event: autocmd BufWritePost $MYVIMRC nested source $MYVIMRC This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,67 +0,0 @@ -
romainl revised this gist
Aug 15, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -61,7 +61,7 @@ augroup END autocmd BufWritePost $MYVIMRC source $MYVIMRC " The solution is to add the 'nested' keyword to that autocommand to allow " other autocommands to be triggered by that event: autocmd BufWritePost $MYVIMRC nested source $MYVIMRC -
romainl revised this gist
Aug 15, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,11 +57,11 @@ augroup MyColors augroup END " NOTE: This won't work if you have an autocommand like the following in your " 'vimrc' because autocommands don't nest by default: autocmd BufWritePost $MYVIMRC source $MYVIMRC " The solution is to add the `nested` keyword to that autocommand to allow " other autocommands to be triggered by that event: autocmd BufWritePost $MYVIMRC nested source $MYVIMRC -
romainl revised this gist
Aug 15, 2017 . 1 changed file with 7 additions and 6 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,7 @@ augroup MyColors augroup END " And of course, we can go one step further and put all our highlights in " a neat little function for maximum readability/managability/maintainability: function! MyHighlights() abort highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 @@ -56,11 +56,12 @@ augroup MyColors autocmd ColorScheme * call MyHighlights() augroup END " NOTE: This won't work if you have an autocommand like the following in your `vimrc` because autocommands don't nest by default: autocmd BufWritePost $MYVIMRC source $MYVIMRC " The solution is to add the `nested` keyword to that autocommand to allow other autocommands to be triggered by that event: autocmd BufWritePost $MYVIMRC nested source $MYVIMRC -
romainl revised this gist
Aug 15, 2017 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -54,4 +54,13 @@ endfunction augroup MyColors autocmd! autocmd ColorScheme * call MyHighlights() augroup END NOTE: This won't work if you have an autocommand like the following in your `vimrc` because autocommands don't nest by default: autocmd BufWritePost $MYVIMRC source $MYVIMRC The solution is to add the `nested` keyword to that autocommand to allow other autocommands to be triggered by that event: autocmd BufWritePost $MYVIMRC nested source $MYVIMRC ^^^^^^ -
romainl revised this gist
Jul 1, 2017 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,4 +39,19 @@ augroup MyColors \ highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 \ highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f \ highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f augroup END " And of course, we can go one step further and put all our highlights in " a function for maximum clarity/readability/managability/maintainability: function! MyHighlights() abort highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f endfunction augroup MyColors autocmd! autocmd ColorScheme * call MyHighlights() augroup END -
romainl revised this gist
Jun 5, 2017 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,9 @@ " Suppose you have weird taste and you *absolutely* want: " * your visual selection to always have a green background and " black foreground, " * your active statusline to always have a white background and " red foreground, " * your very own deep blue background. " " Your first reflex is probably to put those lines somewhere in your 'vimrc': -
romainl revised this gist
Jun 5, 2017 . 1 changed file with 32 additions and 6 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,40 @@ " Suppose you have weird taste and you *absolutely* want: * your visual " selection to always have a green background and black foreground, * your " active statusline to always have a white background and red foreground, * your " very own deep blue background. " " Your first reflex is probably to put those lines somewhere in your 'vimrc': highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f " But it quickly appears that those lines have no effect if you source " a colorscheme later in your 'vimrc' so you move them below: colorscheme foobar highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f " which gives the desired outcome. Everything is fine. In principle. " " But you like to try new colorschemes, or you prefer to have different " colorschemes for different filetypes or time of the day and your overrides " don't carry over when you change your colorscheme. " " This is because colorschemes usually reset all highlighting, including your " own, when they are sourced. " " The solution is to override the desired highlights in an autocommand that's " executed whenever a colorscheme is sourced: augroup MyColors autocmd! autocmd ColorScheme * highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 \ highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 \ highlight Normal cterm=NONE ctermbg=17 gui=NONE guibg=#00005f \ highlight NonText cterm=NONE ctermbg=17 gui=NONE guibg=#00005f augroup END -
romainl created this gist
Jun 4, 2017 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ " Suppose you want: " * your visual selection to always have a green background and black foreground, " * your active statusline to always have a white background and red foreground. " " What you have to do is override those highlight groups in an autocommand " that's executed whenever a colorscheme is sourced. " " This can be done by adding this snippet in your 'vimrc': augroup MyColors autocmd! autocmd ColorScheme * highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000 \ highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000 augroup END