{"id":2750,"date":"2023-03-31T17:21:04","date_gmt":"2023-03-31T11:51:04","guid":{"rendered":"https:\/\/smarttech101.com\/?p=2750"},"modified":"2023-08-31T12:45:27","modified_gmt":"2023-08-31T07:15:27","slug":"how-to-configure-colorscheme-in-vim-neovim","status":"publish","type":"post","link":"https:\/\/smarttech101.com\/how-to-configure-colorscheme-in-vim-neovim\/","title":{"rendered":"How to Configure Colorscheme in Vim\/Neovim"},"content":{"rendered":"\n
In this article, I will talk about colorscheme in Neovim. I will talk about how to install a colorscheme theme in Vim\/Neovim, then how to activate it and put some modifications on it – changing the color and font weight of cursorline, wrong spelling, diagnostics, and completion, markdown headings.<\/p>\n\n\n\n
This article assumes you have set up a basic configuration of Vim\/Neovim<\/a>. If not done, do it. This article also assumes that you are using Vim\/Neovim in your terminal<\/strong>. However, it will definitely help you set your Graphical User Interface (GUI) nonetheless.<\/p>\n\n\n\n \ud83d\udcdd Note:<\/strong> All of these settings have been checked on Neovim. But they should work on Vim too.<\/p>\n\n\n\n By default, Neovim and Vim come preinstalled with some colorschemes. To find out available colorschemes, execute the command – After you are satisfied, you can put Then, source it in your And don’t forget to replace If you are not satisfied with the available colorschemes in Neovim\/Vim, the other way is the installation of a plugin. For this, you can use a plugin manager.<\/p>\n\n\n\n Personally, I use a colorscheme based on pywal<\/a> in Neovim. To install this plugin using the plugin manager Vim-Plug*, run the following command:<\/p>\n\n\n\n *Head on over to this article for a detailed and easy guide on managing plugins using vim-plug.<\/a><\/p>\n\n\n\n For other plugin managers, the installation will be almost the same. Follow their procedure.<\/p>\n\n\n\n \u2694\ufe0f Conflict:<\/strong> The setting To activate this pywal colorscheme in Neovim\/Vim, put the following in your setting file From now on, I am going to tell you how to overwrite the colors provided by these colorscheme. This overwriting has been tasted on the pywal theme. But it should work on other nvim themes.<\/strong><\/p>\n\n\n\n Put the following in your configuration file \ud83d\udcdd<\/strong> Note :<\/strong> Now, I will explain each of these terms one by one. They are used not just in comments <\/strong>but almost everywhere.<\/p>\n\n\n\n To change the weight of the font, use Your terminal should also support these. Most modern terminals like Kitty<\/a> will work but you might face the problem with minimal ones like Urxvt. Configure your urxvt terminal <\/a>based on this article.<\/p>\n\n\n\n Note: <\/strong>Append The terms Use the shell script 256-color-table.sh<\/a> to find out colors. Read this article to learn how to create shell scripts<\/a>. Just run the script in your terminal and choose your favourite color.<\/p>\n\n\n\n Fig: \ud83d\udcdd<\/strong> Note:<\/strong> If the color is beyond 16 i.e. the sum obtained above is more than 16, use If you don’t use Neovim’s LSP, you can skip this paragraph.<\/p>\n\n\n\n To learn about Neovim Language Server Protocol’s diagnostics and how to configure it<\/a>, read this article.<\/p>\n\n\n\n Here is the color configuration I use for diagnostics:<\/p>\n\n\n\n Here, all the Errors, Information, Warning, and Hints will be highlighted in a single color. Change these colors according to your need.<\/p>\n\n\n\n To highlight the symbol under the cursor<\/a>, look here.<\/p>\n\n\n\n To highlight the cursor line and cursor line number, use the following settings:<\/p>\n\n\n\n Where,<\/p>\n\n\n\n \ud83d\udcdd<\/strong> Note: <\/strong>You can also remove the highlights when you enter insert mode<\/strong>. But personally, I don’t use it. Here are the settings for this:<\/p>\n\n\n\n Where,<\/p>\n\n\n\n \ud83d\udcdd Note<\/strong>: You can toggle cursorline<\/strong> using Personally, I do not like the color configuration given by pywal for markdown headings. So I modified those using the following configuration.<\/p>\n\n\n\n Where,<\/p>\n\n\n\n \u2694\ufe0f Conflict<\/strong>: This setting is overwritten by the plugin vim-markdown<\/a><\/p>\n\n\n\n You might want to put different weights and colors on bad spellings, wrong upper\/lowercase letters, etc. For that, use\/modify the following codes:<\/p>\n\n\n\n Use Table of Contents<\/h2>\n\n\n\n
\n
\n
Available colorschemes in Vim\/Neovim<\/h2>\n\n\n\n
:colorscheme<\/code> and keep pressing tabs<\/strong>. Select the colorscheme one by one and hit Enter to test it out. Don’t worry; they will not be applied permanently. After restarting your neovim\/vim window, they will be gone.<\/p>\n\n\n\n
colorscheme <your_chosen_colorscheme><\/code> in your
init.vim<\/code> or
.vimrc<\/code> file to make the changes permanent. As I have recommended in my article on the basic configuration of vim\/neovim, you should partition your settings for better readability<\/a>. So, create a separate colorscheme file,
~\/.config\/nvim\/themes\/<colorscheme_name>.vim<\/code> and put all the colorscheme-related settings in this file instead of
init.vim<\/code> or
.vimrc<\/code>:<\/p>\n\n\n\n
colorscheme <your_chosen_colorscheme><\/code><\/pre>\n\n\n\n
init.vim<\/code> or
.vimrc<\/code> file using the
source<\/code> command:<\/p>\n\n\n\n
source $HOME\/.config\/nvim\/themes\/wal.vim<\/code><\/pre>\n\n\n\n
<your_chosen_colorscheme><\/code> with the name of your chosen scheme.<\/p>\n\n\n\n
Installation of themes in Vim\/Neovim<\/h2>\n\n\n\n
Plug 'dylanaraps\/wal.vim'<\/code><\/pre>\n\n\n\n
set termguicolors<\/code> conflicts with the above pywal theme so remove this setting.<\/p>\n\n\n\n
~\/.config\/nvim\/themes\/wal.vim<\/code><\/p>\n\n\n\n
colorscheme wal<\/code><\/pre>\n\n\n\n
How to change the color, and weight of comments in Vim\/Neovim<\/h2>\n\n\n\n
~\/.config\/nvim\/themes\/wal.vim<\/code>:<\/p>\n\n\n\n
highlight Comment cterm=italic ctermfg=8<\/code><\/pre>\n\n\n\n
hi<\/code> and
highlight<\/code> are the same.<\/p>\n\n\n\n
cterm in Neovim\/Vim<\/h3>\n\n\n\n
cterm<\/code>. Set it to one of the following or to a comma-separated list:<\/p>\n\n\n\n
\n
gui=italic<\/code> to see the similar result in Graphical User Interface (GUI).<\/p>\n\n\n\n
ctermfg and ctermbg in Neovim colorscheme<\/h3>\n\n\n\n
ctermfg<\/code> and
ctermbg<\/code> are used to set the foreground colors (the color used to colorize your fonts) and the background colors respectively.<\/p>\n\n\n\n
color[12,160]<\/code> in the output matrix = color
12+160<\/code> = color 172<\/p>\n\n\n\n
set t_Co=256<\/code> in your vim\/neovim setting file (
init.vim<\/code> or
.vimrc<\/code>)<\/p>\n\n\n\n
Highlight diagnostics in Neovim LSP colorscheme<\/h2>\n\n\n\n
highlight DiagnosticVirtualTextError ctermfg=8\nhighlight DiagnosticVirtualTextInfo ctermfg=8\nhighlight DiagnosticVirtualTextWarn ctermfg=8\nhighlight DiagnosticVirtualTextHint ctermfg=8<\/code><\/pre>\n\n\n\n
Highlight Cursor Line and Cursor Line Number in Neovim colorscheme<\/h2>\n\n\n\n
highlight CursorLine term=NONE cterm=NONE ctermbg=236 ctermfg=NONE\nhi CursorLineNr cterm=NONE ctermbg=236 ctermfg=7<\/code><\/pre>\n\n\n\n
\n
term=NONE<\/code> and
cterm=NONE<\/code> do not put any weight (bold, italic etc.) over the font<\/li>\n\n\n\n
ctermbg<\/code>,
ctermfg<\/code> are just like above.<\/li>\n<\/ul>\n\n\n\n
autocmd InsertEnter * highlight CursorLine term=NONE cterm=NONE ctermbg=0 ctermfg=NONE\nautocmd InsertLeave * highlight CursorLine term=NONE cterm=bold ctermbg=236 ctermfg=NONE<\/code><\/pre>\n\n\n\n
\n
InsertEnter<\/code> tells Neovim when we enter INSERT mode<\/li>\n\n\n\n
InsertLeave<\/code> tells Neovim when we leave INSERT mode.<\/li>\n<\/ul>\n\n\n\n
set cursorline!<\/code>. You can bind this to a key sequence (say,
tc<\/code>) and when you press these keys, cursorline will be turned off and pressing this again, it will be turned on. Use the following settings for that:<\/p>\n\n\n\n
nnoremap tc :set cursorline!<CR><\/code><\/pre>\n\n\n\n
How to highlight markdown headings in Neovim\/Vim colorscheme<\/h2>\n\n\n\n
hi markdownH1 cterm=bold ctermbg=NONE ctermfg=DarkMagenta\nhi markdownH2 cterm=bold ctermbg=NONE ctermfg=DarkMagenta\nhi markdownH3 ctermbg=NONE ctermfg=Magenta\n hi link markdownH4 markdownH3\n hi link markdownH5 markdownH3\n hi link markdownH6 markdownH3\nhi markdownCode ctermbg=8 ctermfg=NONE\nhi markdownCodeBlock ctermbg=8 ctermfg=NONE<\/code><\/pre>\n\n\n\n
\n
markdownH1<\/code>,
markdownH2<\/code>,
markdownH3<\/code>,
markdownH4<\/code>,
markdownH5<\/code>, and
markdownH6<\/code> are for headings
H1<\/code>,
H2<\/code>,
H3<\/code>,
H4<\/code>,
H5<\/code>,
H6<\/code>.<\/li>\n\n\n\n
link<\/code> tells Neovim\/Vim to use the same highlighting for the given headings.<\/li>\n\n\n\n
markdownCode<\/code> and
markdownCodeBlock<\/code> are for the codes and codeblock (codes written in single and triple quotes respectively).<\/li>\n<\/ul>\n\n\n\n
Highlight spellings in Neovim\/Vim colorscheme<\/h2>\n\n\n\n
hi SpellBad ctermbg=NONE ctermfg=NONE cterm=underline\nhi SpellCap ctermbg=NONE ctermfg=NONE cterm=underline\nhi SpellLocal ctermbg=NONE ctermfg=NONE cterm=underline\nhi SpellRare ctermbg=NONE ctermfg=NONE cterm=underline<\/code><\/pre>\n\n\n\n
ctermbg<\/code>
ctermfg<\/code>, and
cterm<\/code> according to your preference. I have removed all colors. Only underlining will be shown to remove the intrusion.<\/p>\n\n\n\n
Highlight the completion popup menu in Neovim<\/h2>\n\n\n\n