How to write a VIM color scheme? - vim

I have been looking around for VIM color schemes and found some great ones out there (esp. by using http://code.google.com/p/vimcolorschemetest/), but I always want to change a few aspects of each one I find. So I've decided now that what I really want to do is make my own, or be able to customize the ones I find on the fly. Basically, what I want to know is:
1) How do I write a vim color scheme -- are there any good (quick) tutorials?
2) How do I add language-specific customizations? Like say for Python, I might be interested in having different colors for classes and methods (is this even possible? What level of customization is possible?). Anything you can tell me about how to customize for specific languages would be fantastic! (esp. python, but also others like C, Java, Ruby would be great)
3) Are there are good, complete (ideally well-commented) templates that I could start from which contain all aspects of a color scheme, like background, text, language specific stuff, and the like?

Vivify lets you interactively create vim colorschemes with color pickers and previews your scheme using several code samples.

I didn't watch the "Creating colorschemes for Vim" episode of VIMcasts, but the others are really good.

colorschemes are actually vim scripts. You use the hi command for coloring, which works like
hi TextType guifg=#hexforegroundcolor guibg=#hexbgcolor gui=bold/italic/underlined/undercurled (assumed you use gvim). If you type :hionly, you get a complete list of text types with their current highlighting
see also http://vimdoc.sourceforge.net/htmldoc/syntax.html#:colorscheme

May be you can find this colorscheme template useful: http://www.vim.org/scripts/script.php?script_id=106
The original description is
"The philosophy here is to provide a ready-to-uncomment list of highlight commands for all the important groups. Then you can deviate from the default until you come up with one you like."

Launch vim, say ":help syntax", it has quick start etc.
For the complete templates look at your installation:
colorschemes are in /usr/share/vim/vimcurrent/colors/
languages syntax in /usr/share/vim/vimcurrent/syntax/

Related

Why do (Neo)Vim Color Schemes not Affect Pmenu, PmenuThumb, CocInfoFloat etc.?

This has been bugging me for a while now. Why is it that I have to define colors for the floating/popup (you name it) menu by myself in (Neo)Vim, when there are all these beautiful color schemes.
I have to put a lot of time and effort into defining somewhat readable (not that pink hell) menus, which eventually might or might not match the underlying color scheme, but won't match anymore, once I decide to change the scheme.
Is there something I am missing?
Neovim inherits its built-in colorschemes from Vim.
Vim's built-in colorschemes are all very old, often predating the completion menu feature, and pretty much unmaintained. They lack many things beyond the completion menu and they are generally in a bad shape.
I started an initiative to modernise the built-in colorschemes but it will take time. If you feel like giving us a hand…
FWIW, Pmenu and PmenuThumb are built-in highlight groups so it is legitimate to expect them to be handled by the built-in colorschemes but CocInfoFloat is not so it is entirely the responsibility of the third-party plugin that defines it to, ideally, link it to a built-in highlight group.
FWIW2, thid-party colorschemes that don't handle 100% of the built-in highlight groups should be considered broken.

How to highlight variables in sublime?

How to highlight variables in sublime text 3? like in netbeans
Your question is not very clear, but here are some options. First, if you're just trying to get variables highlighted differently, you'll need a color scheme with more options than the default Monokai. There are many available on Package Control, but one in particular that I know will work (since I'm its author) is Neon:
You can use the excellent tmTheme Editor to see how this or hundreds of other themes will look (sort of) in different languages. (I say "sort of" because the highlighting engine used on the website is different than the one in Sublime, so there will be some differences. Overall it's pretty good, though.)
On the other hand, if you're trying to highlight all the instances of the $page variable, you'll have to do two things. First, double-click on $page to select it. Then, select Find -> Quick Find All (or use its keyboard shortcut) to select all the instances of $page in the document:
The gutter icons and colored underlines are from the BracketHighlighter plugin
Unfortunately, this is the only way to get this to work when using PHP and other languages like JavaScript that denote variables with a $ or other symbol. If we were to use Python, for example, you could just double-click on page and it would look like so:
As you can see, all the other instances of page have boxes around them. This behavior is hard-coded into Sublime, so while it can be turned on and off, it can't be modified or told to recognize other characters in any way.
Good luck!

Vim context highlighting

I think standard highlighting is useful -- to some extent. When programming with callbacks and nested structures, this does not help. Keywords and strings, they appear everywhere, and it helps when they are shown in a distinct color, but these colors gives no clue about in which scope I am, where I am in a lexical standpoint.
I have heard of context highlighting, in a talk of Douglas Crockford, which I can't remember a url to. The idea is, to highlight lexical levels of scope. Toplevel definitions are colored in color0, inner level block statements are colored in color1, and this repeats recursively every time a new level of scope is introduced. Below is an example for this, using some imaginary node libraries. (Now added a (ish (or scheme lisp)) example)
This is not necessarily for node or javascript. I wonder if there is an editor/vim plugin implementing this kind of feature. I don't know if context highlighting is the word for this, but I can't just find one. Googling for context highlighting brings up results for generic token based highlighting and ConTeXt (which I don't have a clue about).
Does this exists? Is there an editor implements this? And more importantly, can I have this in vim?
Another question which is identical to mine, with no real answer: Is Crockford style Context Coloring implemented in any code editor?
I also couldn't find anything similar, so I wrote one:
rainbow_levels.vim: A different approach to code highlighting.
Of course it is a very simplistic implementation, only considering indentation levels instead of real context, but it gets the job done ;D
Not exactly what you are requesting, but code folding is a powerful feature to let you focus on specific levels of your code. Vim supports folding http://vim.wikia.com/wiki/Folding
Indention guides are very handy also, for focusing in on specific parts of code. The sublime text editor has this (http://sublimetext.userecho.com/topic/98136-indent-guide-highlighting-changed/)
I saw this plugin for vim (https://github.com/nathanaelkane/vim-indent-guides) that appears to do the same thing.
You could possibly create a syntax highlighter that uses the indentation logic of this plugin to change the color scheme. What you describe is more involved where it needs to work not just off the indention, but like a language parser.
There is now a plugin for this in VIM called vim-js-context-coloring. I've only just played with it a little and am not super impressed yet, but it looks promising!
Note: you need to install npm and then run npm install in the directory where the plugin is installed. I regretfully, forgot to read the instructions when I installed it.

Which vim mechanism should I use to implement Markdown list indentation?

I'm looking to beef up the Markdown capabilities of vim a bit (https://github.com/plasticboy/vim-markdown), namely to add some support for auto-creating the next list item while indenting everything properly.
My question is, what vim mechanism is best to implement this in? Is this a task for the highlighting file? Should I cobble together something in SnipMate? I'm glad to do any homework necessary, but I'd like to know where's the best place to start.
Based on a quick snoop through the help, formatoptions and formatlistpat and the related fo-table look like good places to start. I'd start by reading those and then finding existing plugins that use them and figure out how they work.

Vim for Word (or something like it)

Are there any rich-text editors that have Vi(m) keybindings? Specifically, something like Word where I can compose a document with colors, headings, et al. but use Vi(m) bindings to move around and compose?
So if you have to use MS Word and want vim key bindings, there is an add on, but if you are not bound to that I would def. go for LaTeX + the vim latex suite.
Are you familiar with Latex?
Simply put it allows you to format your documents in plain text using tags or commands.
You then "compile" your document into the final format .pdf,.ps, etc.
Ex:
\documentclass{article}
\title{Cartesian closed categories and the price of eggs}
\author{Jane Doe}
\date{September 1994}
\begin{document}
\maketitle
Hello world!
\end{document}
This will allow you to write in vim, but still get professional non plain text output for your documents.
If you like Markdown or Latex, you could use the free open source Rstudio editor, with VIM-mode enabled. Export as either Word, PDF, or HTML etc.
Download Rstudio:
https://www.rstudio.com/products/RStudio/#Desktop
Read about markdown:
http://rmarkdown.rstudio.com/
If you wish to use vim for text editing, but want to, for example have text in different colors, bold it and such ... you can use Txtfmt plugin. It enables you, by using special characters, to "prettify" plain text files a little. They can look quite nice, and it comes handy if you're used to vim, and are, for example, writing documentation for your programs which you'll later just get in word, and make an adjustment or two, and ship off.
If you want to (or have to) stay with Word and don't want to shell out $100 for a ViEmu license, you can try using this AutoHotKey script for providing some basic vi-like functionality. The repo linked also provides a standalone exe to get the same without using AutoHotKey.
There are many good reasons to ditch word entirely, but sometimes that's just not an option :(
The Txtfmt plugin definitely provides the functionality you are looking for. It's a bit like having "rich text" capability for plain text in Vim.
Txtfmt (The Vim Highlighter)
Screenshots
The latest version supports 8 configurable foreground and background colors, as well as all combinations of bold, underline, italic, etc... The highlighting is token-based, but the tokens are rendered invisible by the syntax, and can be inserted with very convenient and intuitive mappings, which don't require you to remember anything: e.g., "bold-underline" could be specified with a string such as bu or ub. The version under development even supports visual maps, which will permit you to select some text and say (for example) "Make this text red, bold-italic", and have the plugin handle insertion/removal of the appropriate tokens automatically. (It's really quite simple and intuitive, however, even with the non-visual mappings.)
Although the plugin is highly configurable, the default settings are appropriate for most users, and the author is more than happy to answer any setup or usage questions...
There's a way of configuring Abiword to use vi key bindings
You can use the text editor of your choice with vim keys (vim, emacs, sublime, atom, vscode ,etc.) and write your document in markdown. Then use an open source tool called pandoc to translate it into almost any other markup language that you want. It is possible to compile your document to rich text formats including MS Word or even MS Powerpoint.
You can costumize your output by using a template.
Pandoc has extensive documentation and uses a richer markup syntax that allows you to do pretty much anything you want with the text. It is being actively developed by the community. Almost any major text editor has a few plugins for pandoc too.
You can use GlobalVim.
It can simulate vim modes and commands in most editing area.

Resources