Wikia

Vim Tips Wiki

Changing the default syntax highlighting

Talk4
1,613pages on
this wiki
Revision as of 15:09, November 12, 2009 by Fritzophrenic (Talk | contribs)

Tip 24 Printable Monobook Previous Next

created 2001 · complexity intermediate · author benji · version 6.0


Here are some pointers to the Vim documentation on syntax highlighting.



 TO DO 

  • I'm parking this information here, while waiting for a better solution.
  • Need a tip on the :highlight command.
  • Mention all the ways text can be highlighted (search, match, syntax, cursorline).
  • Links to tips dealing with colors in an xterm.
  • Links to tips dealing with colorscheme.

Highlight examples

Define two highlight groups and use them to show long lines (see Highlight long lines):

:highlight NearColLimit term=italic,bold cterm=italic ctermbg=yellow ctermfg=darkblue gui=bold,italic guibg=yellow guifg=darkblue
:highlight OverColLimit term=inverse,bold cterm=bold ctermbg=red ctermfg=white gui=bold guibg=red guifg=white
:syntax match NearColLimit /\%<81v.\%>77v/
:syntax match OverColLimit /\%>80v.\+/

Here is a simpler example showing that "highlight" can be abbreviated to "hi", and that you only need to define conditions that are applicable to your usage:

:hi LineTooLong cterm=bold ctermbg=red guibg=LightYellow
:match LineTooLong /\%>80v.\+/

This command shows the current settings for the LineTooLong group:

:hi LineTooLong

Tips with "highlight" in name

Tips relating to color schemes

Also see 53, 111, 284 (listed above).

References

Comments

I want a simple syntax highlighting which does not take attention from the real thing. Color codes are:

Green for comments
Blue for keywords/types
Bluebold for flow-control
Brown or gray for strings and constants
Black (or navy) for the rest

For that purpose I changed the "syncolor.vim" file (and it works best for light background xterm). Every colleague I have shown this syntax-scheme says that it is superb - it works with your intuition, green is definitely just something which can be ignored. I sent a mail to Bram who answered that we have a repository for config files?

I wanted to share my syncolor with vim-users, but I cannot find the appropriate place to do so.

SynColor Comment      term=bold      cterm=NONE ctermfg=DarkGreen ctermbg=NONE gui=NONE guifg=MediumSeaGreen guibg=NONE
SynColor Constant     term=underline cterm=NONE ctermfg=DarkRed   ctermbg=NONE gui=NONE guifg=SlateGrey guibg=NONE
SynColor Special      term=bold      cterm=NONE ctermfg=DarkRed   ctermbg=NONE gui=NONE guifg=DarkRed   guibg=NONE
SynColor Identifier   term=underline cterm=NONE ctermfg=DarkCyan  ctermbg=NONE gui=NONE guifg=DarkCyan  guibg=NONE
SynColor Statement    term=bold      cterm=NONE ctermfg=Blue      ctermbg=NONE gui=bold guifg=SlateBlue guibg=NONE
SynColor PreProc      term=underline cterm=NONE ctermfg=DarkBlue  ctermbg=NONE gui=NONE guifg=SlateBlue guibg=NONE
SynColor Type         term=underline cterm=NONE ctermfg=DarkBlue  ctermbg=NONE gui=bold guifg=Blue      guibg=NONE
SynColor Underlined   term=underline cterm=underline ctermfg=DarkMagenta gui=underline  guifg=SlateBlue
SynColor Ignore       term=NONE      cterm=NONE ctermfg=white     ctermbg=NONE gui=NONE guifg=bg        guibg=NONE

//Donald Axel//--Donald j axel 22:54, November 11, 2009 (UTC)

Hi Donald, and welcome to the wiki!
I have only a vague idea of Vim's color schemes and syntax highlighting, but I have a feeling that syncolor allows the modification of an existing color scheme (or is it to modify syntax highlighting for a particular file type?). People use a color scheme (see :help :colorscheme) to define their standard colors. Bram would have been referring to the fact that there are many color schemes available at vim.org. I just added some more information to Switch color schemes to show how to locate a color scheme there.
I welcome other opinions, but traditionally we would not make a "tip" of a syncolor example on the basis that scripts should be uploaded to vim.org/scripts. We do have lots of scripts here, but the aim is that tips show techniques and tutorial information; simple scripts (not worth uploading to vim.org) are here, but we hope they are mainly educational.
I suppose we could have a tip on syncolor if there was something educational to say about it (it's a mystery to me – is it extending an existing scheme? replacing?) and your code could be shown as a sample. Or, you could make a user subpage to hold the script (which we would move from here to there). For example, you might make page User:Donald j axel/syncolor.
FYI we remove temporary comments such as these after a few weeks. If you have any questions, reply here, or on my talk page, or anywhere, because Fritzophrenic and I check all changes here. JohnBeckett 03:29, November 12, 2009 (UTC)
Hi John: The difference between color scheme and syntax highlighting is that the colorscheme affects the Vim window, syntax highlighting affects only the language elements. The two principles can clash, but Vim syncolor.vim has the excellent notion of using an "if" statement to check whether we are on a dark background or a light background.
Maybe it is hard to understand syncolor.vim differences if you do not try them. The code above is only a section of syncolor.vim. If you do not want to write programs, forget it. However maybe you can imagine the difference between a green comment and a screeming red comment. To my view, as soon as you start using red, purple or magenta the readability decreases.
I am looking into vim.org/scripts but it seems to be mostly text-processing.
I support the idea of a syncolor tip. There are subtle differences between a colorscheme and using syncolor, and from what I understand you should only use one or the other (though I may be wrong about that). The :help is rather cryptic on syncolor; I'd like to see some discussion of syncolor vs. a colorscheme. --Fritzophrenic 15:09, November 12, 2009 (UTC)

Around Wikia's network

Random Wiki