I'd like to implement a syntax file for vim that hides certain characters in the file. Specifically, I want to write an improved highlighter for reading Markdown files that doesn't display some of the formatting characters, preferring instead to indicate them implicitly. For example, I'd like to have things like *bold* render as simply bold with bold text, or to have headings like
My Header
=========
not show their underline, but just appear a different color. I haven't managed to find any examples so far of vim syntax files that hide specific characters from display. Is this something that is possible in vim? If so, how?
To hide syntax items - or just certain characters - the conceal or Ignore arguments can be used. See
:help hl-Ignore
:help syn-conceal
For an example see the syntax file "help.vim" which is part of crefvim. CRefVim is a C-reference manual which is embedded in the Vim help system. The "help.vim" syntax file extends the standard syntax highlighting for help files.
An example. The '$' character is used here to show text in italic:
Maybe this example is a good starting point for you to dig further...
Habi
You could make your own syntaxfile with an according colortheme, using "bold", "italics" and the like. It wouldn't hide anything, so that your syntax must work with the original text.
For example this could be your syntax for headers
In your syntax you would need:
syn match Header '^\s*\u*\.\s.*$' contains=ALL
hi link Header ModeMsg
and in the colortheme
hi ModeMsg gui=bold guifg=NONE guibg=NONE cterm=bold ctermfg=NONE ctermbg=NONE term=bold
then a header like this
1. This is my new header, being bold
would be shown bold, without any markup at all. By the way, you can export it with the TOhtml feature while keeping the highlighting.
Related
I'm trying to force vim to use en_gb as the default dictionary using my vimrc.
My goal is to have it at least for tex files. This is how it is right now.
set spell spelllang=en_gb
vim, unfortunately, can not tell me if color and colour is correct?
If you are just testing those words as the only word in the document, neither is correct: they will both be marked as SpellCap (word not capitalized). If you put in Colour and Color, or if you put another word before them, Colour will not be marked, and Color will be marked as SpellLocal (wrong spelling for selected region). You can see this for yourself using these:
hi SpellBad ctermfg=red
hi SpellCap ctermfg=blue
hi SpellRare ctermfg=green
hi SpellLocal ctermfg=yellow
By default, on many colourschemes, all of those just render the same way (underline), so you can't distinguish them.
You might also find that out by using z= (suggest word) on colour - you'd get Colour as a top correction.
Recently I've been trying to create my own color scheme for vim. I've been mostly just writing in-file, referencing Vivify for hi syntax calls and another site for RGB color codes. After changing most of the color scheme, and creating something that I'm happy with, I noticed that you can't change the color of operators (i.e. +, -, =, || etc.) or the color of methods (e.g. object.method()), as both of these fall under the keyword Normal. Being a java programmer, and having used only the NetBeans IDE up to this point, it's kind of tough not to have any differentiation between objects and their methods. As such I was hoping someone would know of a work-around, or a way to color such forms of syntax not normally changeable via pre-reserved keywords.
Here's the relevant color scheme:
Create a file $HOME/.vim/after/syntax/java.vim with:
" highlight operators
syntax match _Operator "[-+&|<>=!\/~.,;:*%&^?()\[\]{}]"
" highlight methods
syntax match _Paren "?=(" contains=cParen,cCppParen
syntax match _memberFunc "\.\s*\w\+\s*(\#=" contains=_Operator,_Paren
" colors
hi _memberFunc guifg=#00FF00 guibg=NONE gui=none
hi _Operator guifg=#FF0000 guibg=NONE gui=none
" to resolve conflict with comment markers
syntax region _Comment start="\/\*" end="\*\/"
syntax match _Comment "\/\/.*$"
hi link _Comment Comment
When I'm editing (La)TeX files, Vim (with the default colorscheme) uses a bold font for the contents of \textbf{}, inverts the background color of \textit{}'s contents, etc.
I would like it to also underline the contents of \underline{}.
I've come up with a rather hacky solution that works in most cases, but breaks when the \underline{} contains a closing brace }:
highlight underline term=underline cterm=underline gui=underline
match underline /\\underline{\zs.\{-}\ze}/
(The underline highlight definition is necessary because Underlined changes the color of the text.)
How can I do this more elegantly?
I've looked at /usr/share/vim/vim74/syntax/tex.vim, but I can't seem to adapt something like syn region texBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" end="}" concealends contains=#texBoldGroup to my needs…
Place the cursor over \underline{foo} and type that command:
:echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
It will tell you which highlight group is used for that symbol. Once you have that information, you can try to add your highlight line to:
~/.vim/after/ftplugin/tex.vim
If the only problem is \} inside the \underline{}, then here's an improved regex:
/\\underline{\zs\(.\([^\\]}\)\#<!\)\+\ze}/
Alternatively, it is indeed possible to properly add it to syntax/tex.vim: add a syn cluster texUnderlineGroup (and add it under contains= for all appropriate existing clusters), add a syn region texUnderlineStyle, and finally add a hi texUnderlineStyle.
I'm using VIM via terminal (SSH) and want to modify my syntax coloring settings in VIM to make the function_name Yellow for Lua programming. Unfortunately, I can't figure out how to do that.
For example, in the code below - I want my VIM to syntax color myFunc yellow
local function myFunc(arg1)
...
end
I've been able to figure out how to make function yellow, by using this code below:
hi luaFunction ctermfg=Yellow
But this code does not color the word myFunc yellow (and frankly, I'd rather not syntax color function at all)
Question: Any ideas how I can syntax color the function_name in Lua?
Another (more complex) regex to match the function name.
:hi luaCustomFunction ctermfg=yellow
:syn match luaCustomFunction "\(\<function\>\)\#<=\s\+\S\+\s*(\#="
This uses a look-behind to match the word function. Then after 1 or more spaces it will highlight any word that has a parenthesis as the first non whitespace character after it.
This only highlights the function name. It does not highlight the parenthesis.
I think if you put these commands in .vim/after/syntax/lua.vim it should work.
The problem with putting them in your vimrc is that sometime after the vimrc is sourced the syntax highlighting file is sourced and generally the first line in there is syn clear. (Which wipes the custom syntax highlighting you just set)
This very naive implementation works with your sample:
:hi luaCustomFunction ctermfg=yellow
:syn match luaCustomFunction "\s\+\zs\S\+\ze("
It is obviously very limited but at least you get a starting point. Read :h syntax for further help.
How about:
hi def link luaFunction Function
hi Function ctermfg=Yellow
This may seem like a simple question but I've probably spent hours looking for this to no avail. How do I create a colored line on the right of line numbers in Vim? Like this:
Not sure about the line, but you can change the foreground color to add some contrast.
From http://vim.wikia.com/wiki/Display_line_numbers:
You can change the color used for the line numbers. For example:
:highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE
You would need to change the Vim source code for that. Such a patch is unlikely to be included in Vim, though, because one of Vim's design principles is that its features should be available on all platforms, and anything that doesn't fit into the character raster cannot be implemented in the console. (And even workarounds would require special Unicode characters to emulate such a line.)
Unfortunately, you cannot hack something like this with built-in features: Both sign column and fold column are displayed to the left of the number column. Is that visual distinction really so important for you?!
Unfortunatrly you can't add a line there: there's no option for that and, I believe, no hack.