VIM colors in Ubuntu20.04 terminal - vim
After going down the wrong rabbit hole, looking at themes for terminal in Ubuntu20.04 I realized what I really needed to change was the colorscheme in vim. I have found they are listed in /usr/share/vim/vim81/colors/*.vim
One of the things I don't understand, is that Putty seems to have the colors I like, am used to, and can most easily see, when when I type ":colorscheme" while a file is open in the vim editor, it outputs "default". I DO NOT understand why the default theme looks correct to me in PuTTy, but not in Terminal. If I had the option of changing the font family and size in PuTTy in Ubuntu20.04 I would likely just use it. As it is, it is too small, I can barely see the font. Thus, I need to use terminal. However, the colors make it hard for me to see.
The colors I want (specifically for Python, but putty just always has the right colors) are the ones that PuTTy seems to be using when I type ":colorscheme default" but I want these colors for terminal.
Does anyone know how to get "terminal" to display the same colors that PuTTy displays? Or has anyone created a custom "*.vim" color file that I can download and use as the colorscheme in VIM for my terminal?
Terminal, using ViM81's :colorscheme=default:
VIM, using ViM81's :colorscheme=default:
If any one can provide a link to a page that tells me what to do, or to a colorscheme.vim file for terminal's VIM, I'd really appreciate it.
A colorscheme is essentially a sequence of Ex commands like this one:
highlight Foo cterm=NONE ctermbg=red ctermfg=224 gui=NONE guibg=#ff0000 guifg=#ffdfdf
that define, for a given highlight group (for Foo, here):
a text style for terminal emulators with cterm,
a background color for terminal emulators with ctermbg,
a foreground color for terminal emulators with ctermfg,
a text style for GUI Vim with gui,
a background color for GUI Vim with guibg,
a foreground color for GUI Vim with guifg.
Since you are talking colors and terminal emulators, only ctermbg and ctermfg are relevant.
ctermbg and ctermfg can be given different kinds of values whose effect might differ depending on your environment:
1-15 would mean "use color at given index in the so-called ANSI palette",
red would mean "use color with given name in the so-called ANSI palette",
16-255 would mean "use color at given index 224 in the so-called xterm palette".
There are literally thousands of custom colorschemes in existence and colorscheme authors may favor one notation over the other, mix them, or even don't use them at all because they only care about GVim. "YMMV" is not a joke when talking about Vim colorschemes.
What notation is used by the default colorscheme mostly depends on your environment, which has thus a lot of influence on how things look.
For example, if your $TERM is something like xterm, Vim assumes that your terminal emulator can only display 8-16 colors so it uses the first notation. This means that the colors you see are all taken from your terminal emulators so-called ANSI palette, which a) changes from terminal emulator to terminal emulator, and b) can generally be modified by the user anyway. In this context, there is no way whatsoever for Vim to make any guarantee about what colors will be used in the end.
If your $TERM is something like xterm-256color, Vim assumes that your terminal emulator can display 256 colors so it uses, and that's really annoying, a mix of the first and third notations. Colors 16-255's big advantages over colors 0-15 are a) that they are not easily changed by the user, and b) that they can reasonably be expected to be the same on most terminal emulators that implement them. The annoying bit is that Vim uses lots of colors in the 0-15 range, which can't be trusted, in combination with colors in the 16-255 range, which can be trusted.
The ultimate consequence is that default can't be expected to be consistant across terminal emulators without some fiddling.
Where to go from there?
First, if you expect n Vims, in n terminal emulators, on n platforms to behave the same, the very least you have to do is:
make sure $TERM matches,
make sure it actually is the exact same Vim version with the exact same patches applied,
make sure colors 0-15 of all terminal emulators are the exact same,
and, since you mentioned font size, make sure you have the exact same font installed everywhere and all your terminal emulators set to use it at the exact same size.
If you want to stick with default, then checking all of the above should get you closer to where you want to be. If you can't, then you can give up right away.
Second, Vim comes with lots of alternative colorschemes out of the box, so you could try them and see if there is one that works better for you:
:colorscheme <Tab>
Third, as mentioned above, you could try some of the many custom colorschemes publicly available. Be aware that they may come with different sets of features and different requirements.
The default colors for Vim are specified in terms of the 16-color ANSI palette. This palette goes back to EGA, and it roughly defines eight colors, possibly with a bold (bright) version of each. The difference that you're seeing is that the definition is approximate. For example, color 1 is red and color 4 is blue, but nobody mandates what color that red and blue are. Specifically, in many cases, the regular (non-bright) yellow is brown.
If you want to set the colors to be different in Ubuntu, you should be able to configure the terminal emulator in its settings. GNOME terminal, which is what it looks like you're using, should allow this. The Wikipedia page on ANSI terminal codes contains information on which actual colors are mapped to different color numbers.
Thanks to romainl I got it all working the way I wanted it to.
In VIM, when I typed in ":colorscheme" it output "default",... YET when I typed ":colorscheme default" it actually changed the colors to ALMOST match what was in PuTTy. Then, I just had to add a few adjustments to my ~/.vimrc and ~/.vim/syntax/python.vim files. Below are those adjustments...
In my .vimrc file, I had to move:
syntax on
filetype detect
filetype plugin on
From the bottom of my .vimrc file, to almost the very the top, as it was getting overwritten by something. Then, I added one line above that (:colorscheme default (to force it to switch to the "real" default")), and 5 lines below it. Now my .vimrc contains (amongst MANY other customizations):
colorscheme default
syntax on
filetype detect
filetype plugin on
hi Comment ctermbg=black ctermfg=green cterm=None
hi String ctermbg=black ctermfg=1 cterm=None
hi Statement ctermbg=black ctermfg=yellow cterm=None
hi StatusLine ctermbg=0 ctermfg=7
hi StatusLineNC ctermbg=252 ctermfg=238 guibg=#d0d0d0 guifg=#444444
Additionally, my python syntax file (located at ~/.vim/syntax/python.vim) needed these adjustments:
hi Statement ctermbg=black ctermfg=yellow cterm=bold
hi pythonStatement ctermbg=black ctermfg=yellow cterm=None
hi Conditional ctermbg=black ctermfg=yellow cterm=None
hi pythonComment ctermbg=black ctermfg=green cterm=None
hi pythonString ctermfg=1 cterm=None
hi pythonQuotes ctermfg=blue cterm=bold
Again, special thanks to the answer above from: romainl with his/her help, and the above customizations, I was able to get my VIM colors in Ubuntu20.04 Terminal to match my VIM colors in PuTTy that I was used to.
P.S. My term-type is xterm
I'm not sure if this is exactly what you are looking for, but... I ran into a problem that the color schemes in my terminal did not look like they looked on the previews on https://vimcolorschemes.com.
Adding the following lines solved to ~/.vimrc solved problem for me:
if !has('gui_running')
set t_Co=256
endif
set termguicolors
Related
How to use bolt/italic fonts in a Vim colorscheme?
I've been making a custom colorscheme for myself, but I can't seem to figure out how to apply bold/italic font to my code syntax. I've got a series of lines like let s:keyword=#0197F4 to define colors to variables, then more lines below like exe 'hi Keyword guifg='s:keyword' gui=bold' to assign colors and text decoration. This is from a template I found, not my original code. I've got set termguicolors in my .vimrc as well. However, the gui=bold part doesn't actually seem to do anything. I'm using Vim in the terminal (iTerm2) and I know it's capable of bold text, because when I load up my .vimrc, I can see that it does work. For example, the phrase g:python_highlight_all is bold. I'm using python code snippets to test my highlighting, if that matters.
gui, guibg, and guifg are attributes specific to GUI Vim, cterm, ctermbg, and ctermfg are attributes specific to color terminals. You say: the gui=bold part doesn't actually seem to do anything and then: I'm using Vim in the terminal Since you are running Vim in a terminal emulator, the right attribute is rather obviously cterm, not gui.
Where to find list of colors for vim?
I am trying to customize my cursorline by doing something like this: :highlight CursorLine ctermfg=White ctermbg=21 cterm=bold Is there a place that shows what the actual color options are? For example, it looks like mine has thousands of options (ctermbg=2121 is different than ctermbg=2122, etc.), or is there a way to enter in a hex code instead, such as: ctermbg=#EEEEEE ? Where can I find this?
If your underlying terminal is truly capable of TrueColor, you can just say to Vim: :set termguicolors. Then all ctermXX will be ignored and guiXX will be used instead even in console Vim. However, if your terminal is not capable of TrueColor then "those color numbers" are in fact just "palette indexes", and their meaning depends on your terminal setup. For standard "xterm" and such you can google for appropriate tables. There are quite a few webpages out there.
vim colorscheme showing incorrect colors
I just grabbed the "Ultimate Vim Distribution" (http://vim.spf13.com/) that came with a bunch of colorschemes. For some reason, setting a colorscheme inside my .vimrc (e.g. "colorscheme corporation") results in completely different colors than the colorscheme actually defines. Moreover, manually entering :colorscheme corporation once vim has loaded a file results in the colors changing to the correct scheme. Upon loading a file, ":colo" and "echo g:colors_name" both print "corporation", as they should. "t_Co" is set to 256 before the colorscheme is set (if that matters). I'm all out of ideas!! Thank you!
It seems to be a GUI only color scheme. There's not much you can do unless you want to write a terminal version. When you see a color scheme not behaving as expected you can always try it in GVim with :gui<cr>. If you look at the code it has styling only for GUI. Here's an example line from this scheme: hi FoldColumn gui=italic guifg=#192224 guibg=#A1A6A8 And here's a line from Molokai which is a color scheme both for the GUI and the terminal versions of Vim: hi FoldColumn ctermfg=67 ctermbg=16 As you can see the colors aren't RGB values. cterm stands for color term.
When the colorscheme only defines colors for GVIM, the GUI version of Vim, you can, if you have a high-color terminal that supports 88 or 256 colors, use the CSApprox plugin to convert (once or automatically during Vim startup) the color definitions for the terminal.
vim wombat colorscheme not showing up correctly in xterm
I put the wombat.vim in my ~/.vim/colors/ and i have :colorscheme wombat in my .vimrc and yet the colorscheme is not what wombat looks like. The scheme looks like a cross between two schemes. Not sure what is wrong. Any ideas?
Looking at source code of wombat.vim I realized that it sets values of guifg and guibg, and those are for a GUI vim. Not my case. So I download a version which set values ctermfg and ctermbg for non-GUI versions. You can get the file here and leave it in: ~/.vim/colors/wombat256.vim Colorschemes work in a 256-color terminal. Check your term value :set term? In my case the value was xterm, so changed it to xterm-256color and worked. :set term=xterm-256color
Try with another terminal emulator or, better yet, using gvim. Most of the time discrepancies between the expected colours and the ones you actually get are due to the way your terminal handles them, in particular for colour schemes outside the standard 16 colours palette.
Remove the colon at the beginning of the line in your .vimrc
vim colorschemes not changing background color
I try to apply various color schemes in vim that I have seen on the net. Whatever scheme I choose, the background remains white, even though screenshots of the applied scheme shows that the background should be colored. In some schemes, some of the background change color, but space right of lines containing text still remains white. I'm using Vim 7.2 on a mac. I have just started messing with non-gui applications, so everything should be pretty much as it was out of the box.. Does the overall settings for the terminal window have something to do with it? When running macvim, everything looks ok. Its only when starting vim from the terminal things looks strange..
I have this in my .vimrc and it solved this problem for me using while using PuTTY. set t_Co=256 set background=dark colorscheme mustang highlight Normal ctermbg=NONE highlight nonText ctermbg=NONE It's important to load the colorscheme before the ctermbg settings in .vimrc because they need to override the same ones set by the colorscheme. This also means you can't switch colorscheme while Vim is running and expect it to work.
I'm adding a second answer from me because it's very different from my first answer and may point to actual problem. If you look at the actual website for the colorscheme here: Molokai website you will see a question very similar to yours. Here's answer given, which suggests trying command :set t_Co=256 in your vimrc to see if it fixes things: "- Make sure you’re using a console terminal capable of 256 colors; not all of them do (particularly on mac). You might need to explicitly force Vim to use that by doing “set t_Co=256″ on your .vimrc file. - The windows console is well… totally unsupported, that only does 16 colors so it’s a mess"
In linux I had export TERM=xterm-256color in my .bashrc. That caused vim to look like this (after setting set t_Co=256): When I removed that line from my .bashrc and opened a new terminal (exec bash didn't do it) This is what I get:
Terminals are usually limited to 256 colors while GUI are only limited by color depth of your desktop environment, typically 2^32. So even if there is lots of vim color scheme available around, implicitly they are often designed for the GUI and won't work for the terminal version. If you look at color schemes on vim.org, there is often a mention of GUI or 256. So you have to chose which to use depending on the context. To convert a GUI scheme to terminal you can use the following plugin : CSApprox. You can also use a different colorscheme depending on the context, add the following in your .vimrc: if has("gui_running") colorscheme [using any color you want] else colorscheme [using 256 colors] endif
I think the problem could be the way the default color is changed by the colorscheme. I've looked at some colorschemes that set default merely by: set background=light or set background=dark Not sure what limitations of those are. I don't think those work in terminals. In any case, you should be able to manually set background in a terminal by using the 'Normal' highlight. Insert it into a spot before most of the 'hi' commands in the colorscheme file and it should provide defaults they will work with. For example: hi Normal ctermbg=White ctermfg=Black guifg=Black guibg=White Change ctermfg (color terminal foreground) and ctermbg (color terminal background) to be whatever you want (or whatever color you were expecting to see in the colorscheme but now aren't seeing). (Remember, though, if the colorscheme already has a setting for hi Normal then this probably isn't your problem.) For ctermbg and ctermfg you can enter color names, but I think there is only a fairly limited number: Black DarkBlue DarkGreen DarkCyan DarkRed DarkMagenta Brown, DarkYellow LightGray, LightGrey, Gray, Grey DarkGray, DarkGrey Blue, LightBlue Green, LightGreen Cyan, LightCyan Red, LightRed Magenta, LightMagenta Yellow, LightYellow White Otherwise you should be able to use a number from 0 to 255 in place of the color name. Or this script gives rough idea, and lets you see how you could also set up to use more color names: Vim script with color settings Also, there are a number of scripts that help you use or convert colorschemes written for gui for use with cterm. E.g.,: Colorscheme support for cterm Does the overall settings for the terminal window have something to do with it? Maybe, but I'm pretty sure a properly written Vim colorscheme will override any terminal settings you've made. At least they do for me in Windows and on Ubuntu. . .
You need to add set termguicolors to your ~/.vimrc I tested t_Co=256 and other options, but none worked, only set termguicolors After this you can use the command set bg=light or set bg=dark to see witch one looks better (some vim color schemes accept both options). Here is a list of terminals that are compatible with termguicolors: https://gist.github.com/XVilka/8346728#now-supporting-true-color
I had the same problem and found out that the answer to this question is actually threefold, where fixing only two of the three isn't enough. You'll need to have: 256-color support in your terminal - Putty with default settings does have this Vim has to recognize that the terminal is 256-color capable: "set t_Co=256" in your .vimrc will do it The color scheme needs to have support for color terminals with ctermbg and ctermfg attributes for highlights, not just the gui*-versions. http://www.vim.org/scripts/script.php?script_id=2682 should be able to provide these automatically, and CSApprox I'm using most definitely does, but requires either +gui -compiled Vim or a recent enough Vim version (7.3 or newer). The third one seems to be the most commonly missed requirement. I wrote a short piece on my own fumblings on this subject just this morning: http://codeandlife.com/2013/09/22/vim-colorschemes-with-putty-aka-gui-vs-xterm-color256/ Final gotcha that happened to me while trying different settings was that when the colors did work, only areas of screen with text had the proper background color. Re-checking Putty Terminal setting "Use background colour to erase screen" fixed that final issue for me.
Does the overall settings for the terminal window have something to do with it? Yes, terminal parameters override vim parameters (at least in OSX and iTerm). For example, I have a following script in /Users/[username]/.bashrc setBackground() { osascript -e "tell application \"iTerm\" set current_terminal to (current terminal) tell current_terminal set current_session to (current session) tell current_session set background color to $1 end tell end tell end tell" } vim() { (setBackground "{65025,65025,65025}" &) (exec vim $*) } The above remaps terminal vim command to execute a background color change before executing vim. Background color function is applescript (I copied the script from somewhere...). It works for iTerm. I belive that you can adapt this to work with terminal (apple product + apple script -> should work). br, Juha
Use this rule if you use Vim through SSH: Add to your local .bashrc: export TERM=xterm-256color Remove from .bashrc any TERM definitions. If you use same .bashrc on both (local and remote), use temporary environment variable and never set TERM globally: alias color-ssh='TERM=xterm-256color ssh user#host'
This works for me for switching backgrounds: colorscheme hemisu function! g:ToggleBackground() if &background != 'dark' set background=dark else set background=light colorscheme hemisu endif endfunction nnoremap <silent> <F3> :call g:ToggleBackground()<CR> Also try setting light background to something like ctermbg=231, so that tmux handles it better.
I have similar issue that the background color of indentation guides (nathanaelkane's vim-indent-guides) cannot be displayed in my Windows Cygwin's mintty terminal. I solved the issue with a line Term=xterm-256color in ~/.minttyrc (equivalent to set via mintty's Options GUI: Terminal -> Type -> xterm-256color. This has the effect export TERM=xterm-256color. Without this, mintty default to TERM="xterm", which result in vim's t_Co=8 (instead of t_Co=256) and cannot show some background color. Checklist: echo $TERM in bash should give xterm-256color. in vim, :set t_Co should give t_Co=256.