I'm building a color scheme from scratch and as I came past the syntax group I noticed a lot of inconsistency overall.
hi Comment ctermfg=129 ctermbg=129 cterm=italic
hi Boolean ctermfg=3 ctermbg=none cterm=bold
The comments are basically ignored as they should be both purple and italic, instead they're both a different color and not italic. The booleans as well both show a different color but they do appear to be bold.
hi String ctermfg=10 ctermbg=none cterm=italic
The string on the other hand has no trouble whatsoever.
I used a Javascript and Python file for testing here but it messes up everywhere (CSS, HTML, Rust, C, Shell).
I'm using rxvt-unicode and have no trouble assigning the purple color to the string.
Kind of unsure on how to proceed here. What could be the problem?
First ensure that you are looking at the correct line, i.e., that code is using the highlight group that you think it should. You could use the following mapping from the vim tips:
map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
By hitting F10 it will display the highlight group off the word under the cursor.
If the problem remains you could:
switch the terminal to check if it the problem is specific to urxvt
ensure that no plugin/setting is interfering by following the procedure on Vim FAQ 2.5 - "I have a "xyz" (some) problem with Vim. How do I determine it is a problem with my setup or with Vim? / Have I found a bug in Vim?"
check the Vim FAQ on syntax highlighting
You may also be interested on ColorSchemeEditor plugin:
This plugin provides a GUI tool which simplifies creating/editing Vim
colorscheme files. It consists of a Vim plugin as well as a Python
program, and utilizes Vim's command server interface |clientserver|
for communications.
Related
I am pretty noob at Vim still, pardon my ignorance
"Boundary" whitespace is any whitespace except single spaces between words, paraphrasing from VSCode docs:
I want to mimic this same behavior in Vim (ideally with no plugins).
An example of how this feature looks in VSCode:
There aren't many resources that I found on this topic. There is Render space if it have multi space in Vim, which addresses this exact same feature (previous example image shown is from that question), but the provided solution does not work exactly as expected.
This is an example of how boundary whitespaces look after trying out that stackoverflow solution:
While the '·' character is shown when there are 2 or more spaces in a row, which is desired, they are also shown highlighted, which is not what I expected
Moreover, if I place the cursor on a line that contains consecutive spaces, they disappear (or are highlighted into invisibility, whatever is happening that renders them invisible)
Excuse my newbie comments in my .vimrc; the rest of the file is commented out
This is another example, in VSCode, of the desired behavior:
Am I missing something from that previous question? Is the highlighting of whitespaces normal or a different issue on its own? Thanks in advance!
The feature you are looking for can be enabled with :help 'list' and customized with :help 'listchars':
The result above can be obtained by adding the following lines to your vimrc:
set list
set listchars=eol:↵,lead:·
If your color scheme makes those characters too visible, you can override its NonText and SpecialKey highlight groups (mentioned in :help 'listchars') to make them more bearable. For example:
augroup MyColors
autocmd!
autocmd ColorScheme * hi NonText ctermfg=235 | hi SpecialKey ctermfg=235
augroup END
colorscheme foobar
Note that listchars was more limited at the time the linked question was answered so, while it was more or less valid at the time, it is no longer necessary to use the conceal feature for this.
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
So I have been using spf13-vim recently, and I have tried changing the default colorscheme, but for some reason when I do I get strange highlighting of words. The highlighting seems to depend on the filetype such that my .txt and .py file will look different.
As an example, the following image shows the highlighting effect on headnode, clusterRun, bwa, and vt. This only occurs when I alter the colorscheme from default. So is there a way to stop this from happening?
You need to find out which syntax group causes the highlighting. :syn list shows all active groups, but it's easier when you install the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin. When you have the name of the offending syntax group, you can investigate where it comes from; (the last lines of) :scriptnames may help.
If you cannot find the highlighting this way, it may be spell checking; this goes on top of the syntax highlighting. You can list the corresponding highlight groups via
:hi SpellBad | hi SpellCap | hi SpellLocal | hi SpellRare
If you don't want spell checking,
:set nospell
turns it off.
Soap Box
Vim "distributions" like spf-13 and Janus lure you with a quick install and out-of-the-box settings, but you pay the price with increased complexity (you need to understand both Vim's runtime loading scheme and the arbitrary conventions of the distribution) and inflexibility (the distribution may make some things easier, but other things very difficult). Vim is incredibly customizable, using someone else's customization makes no sense.
I am running vim 7.3 on several machines. By default MatchParen is enabled on all of my instances. Using gvim on my windows machine, it is doing exactly what I want - when my cursor is on a bracket, paren, etc. it visually highlights the match. It does not affect cursor navigation. However, on my Ubuntu boxes, when I move the cursor onto the character, it actually jumps to the match.
I'm sure that the behavior is caused by MatchParens because if I do a :NoMatchParen, it stops. Unfortunately, I also don't get the highlighting at that point. I can't figure out where my settings differ, though.
I'll like you even more if you can point me towards a plugin that will always highlight the closest enclosing pair of characters around my current position (like a code oriented version of MatchTagsAlways)
When showmatch is set, the cursor is actually jumping, and the following line fixes the problem:
set matchtime=0
More details:
http://vimdoc.sourceforge.net/htmldoc/options.html#'matchtime'
Just like FDinoff said in the accepted answer, this is probably only a problem of colors.
So if the color of the matching "paren" disorients you, tweaking colors of background and foreground is likely the solution.
But HOW do you do this?? ^^
I've had quite a journey through the vimdoc (it was not easy).
I've tested a whole bunch of variables and found that the relevant tweak is the [hi]ghlight command and specifically the MatchParen group.
The solution
Adding this in my .vimrc did the trick:
hi MatchParen ctermfg=208 ctermbg=bg
Note that vim config files are read from top to bottom, and some types of "words" are matched by several options. For example, a boolean could also be a keyword. Thus you have to pay attention to the order of these options.
How does this work?
My problem was that the background had the flashy color while the foreground had the color of the background of my terminal, which made it really confusing. Thus switching colors was the solution for me. But maybe you will have to tweak it differently.
First, you can check the current value for highlight MatchParen by entering the following command (while inside vim, in normal mode):
:hi MatchParen
You'll see hi MatchParen followed by XXX in the current style, followed by a list of argument=value separated by spaces.
The important arguments are ctermfg and ctermbg for the "terminal" vim, guifg and guibg for the "gui" vim. (Where fg means foreground and bg means background)
You can change a value and see the result in real time. Just put your cursor over a match character and enter the following command:
:hi MatchParen SomeArgument=SomeValue
This will not be saved, so don't worry. When you find a proper combination of values, you can add them in your .vimrc as shown above.
Personally, I set ctermfg to 208 (orange color) and ctermbg to bg (a keyword for the current background color, if known by vim).
If you use vim in a gui, take a look here for the available choice of colors.
The cursor isn't jumping. The color scheme probably has defined bad colors for the MatchParen highlight group which makes it look like the cursor is jumping.
Running default gVim (v7.4.461) without any configuration (i.e. no .vim files) in openSUSE 13.2 Legacy 32 Bit, :set showmatch? reveals that showmatch is on at start, which is not Vim's stated default behaviour. We can account for this by adding :set noshowmatch in our .vimrc.
I came across this question:
https://softwareengineering.stackexchange.com/questions/87077/how-can-a-code-editor-effectively-hint-at-code-nesting-level-without-using-inde
and thought that Vim might be able to do something similar as well with a plugin.
I believe the indentation level could be indicated with the a sign (icon in GUI, text with highlighting in term). The piece I'm not sure about is displaying the lines without indentation. Does anyone know, is it possible and/or how you would do it?
This question is not whether or not displaying indentation levels in this manner is desirable; but how to accomplish it in Vim.
You could use the conceal feature that is new in 7.3.
Here is a function that does roughly what the article is describing (for spaces; accounting for tabs instead would be a fairly trivial addition):
function! IndentationHeatMap()
set conceallevel=1
for i in range(1,9)
let indentation = repeat(" ", &sts * i)
exe 'syntax match NonText "^' . indentation . '" conceal cchar=' . i
endfor
endfunction
A solution closer to what you are requesting might use conceal to hide all leading whitespace with
syntax match NonText "^\s\+" conceal
and then use signs to provide the indicators based on custom calculations.
Note: NonText in these syntax commands is an arbitrary highlight group.
Take a look at these plugins: Indent Guides and IndentHL
Both have screenshots.