How do I force vim to highlight the following environment:
\begin{dmath*}
2 + 2
\end{dmath*}
the same way as
\begin{equation*}
2 + 2
\end{equation*}
?
i.e I want the dmath environments (in its plain and starred versions) to be highlighted the same ways as the equation (plain and starred) environment.
I pasted your question into Vim, :setf tex, and then used the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin to find out that the corresponding syntax group name is texMathZoneES.
Then I opened $VIMRUNTIME/syntax/tex.vim and searched for it. I didn't find that directly, but something like this:
call TexNewMathZone("E","equation",1)
Then I looked up :help ft-tex-syntax (completed from the command-line via <C-D>), and found under :help tex-math a nice documentation. With that, I created the following solution:
call TexNewMathZone("M","dmath",1)
You can put that into ~/.vim/after/syntax/tex.vim, as suggested, to make it permanent. Easy, isn't it?!
Related
Does anyone know a way to color highlight function calls in Vim?
I know that some plugins could do something like that by keeping record of tags, but with what I've found online, I could not figure out how to make it work.
I've tried using easy tags (which, by the way, doesn't seem to be maintained anymore) and gutentags, but to be quite honest, I haven't come much close to make any of them to work.
On the other hand, I imagine that it would be quite simple to implement a script to highlight anything that lies between a dot and a left parentheses or a blank space and a left parentheses (as in .anyCodeAtAll(), anotherCode()), but I have no idea how to do it. It would be a incomplete solution of course, but it would be good enough for my purposes at the moment.
Does anyone know how to make that work?
I have something like that in my configuration, but it's quite language specific. For example for Golang, I have a ~/.vim/after/go.vim which contains:
syntax match goCustomParen "(" contains=cParen
syntax match goCustomFuncDef "func\s\+\w\+\s*(" contains=goDeclaration,goCustomParen
" Exclude import as function name, for multi-line imports
syntax match goCustomFunc "import\s\+(\|\(\w\+\s*\)(" contains=goCustomParen,goImport
syntax match goCustomScope "\."
syntax match goCustomAttribute "\.\w\+" contains=goCustomScope
syntax match goCustomMethod "\.\w\+\s*(" contains=goCustomScope,goCustomParen
highlight def link goCustomMethod Function
highlight def link goCustomAttribute Identifier
highlight goCustomFuncDef ctermfg=13
highlight goCustomFunc ctermfg=43
highlight goCustomAttribute ctermfg=247
highlight goCustomMethod ctermfg=33
And for Python, I have a ~/.vim/after/python.vim:
syntax match pyCustomParen "(" contains=cParen
syntax match pyCustomFunc "\w\+\s*(" contains=pyCustomParen
syntax match pyCustomScope "\."
syntax match pyCustomAttribute "\.\w\+" contains=pyCustomScope
syntax match pyCustomMethod "\.\w\+\s*(" contains=pyCustomScope,pyCustomParen
highlight def link pyCustomFunc Function
highlight def link pyCustomMethod Function
highlight def link pyCustomAttribute Identifier
highlight pyCustomFunc ctermfg=43
highlight pyCustomAttribute ctermfg=247
highlight pyCustomMethod ctermfg=33
In each case, the first block defines what is a function, a method, an attribute, and so on, the second block link these custom definition to the generic classes "Function, Identifier..." and the 3rd block defines the colors.
The files need to be in the after directory to be executed after the colorscheme and highlights definitions.
Here's a side by side comparison of with and without these settings (look on the last 3 lines):
Unless someone has a better solution, you could adapt the above for the language you need it.
It might be that you have not installed your plug-in correctly.
Try following these steps (or retrace your steps) and see if it works / missed any steps out:
cd ~ Go to home directory.
vim .vimrc open .vimrc
Insert:
call plug#begin()
Plug 'xolox/vim-easytags'
call plug#end()
easytags#Options states easytags should work out of the box, but you could add option here in the
.vimrc file now or later,
e.g. put:
let g:easytags_syntax_keyword = 'always'
afer the call plug block.
Anyway.
:wq write quit the .vimrc
source ~/.vimrc unsure if required as will do later
vim test.js open vim with test.whatever language you know.
:PlugInstall in vim
Here might take a bit of time.
Then :q out of that window.
:source ~/.vimrc this is needed
Then test out to see if you have syntax highlighting.
I'm pretty sure this is along the right lines. Might be misspelled plugin name.
I am making changes to an existing C code. If I just want to check my changes, I can easily use vimdiff for that, with old & modified files.
What I want is to limit some syntax highlighting to just the diff part.
Particularly I need to highlight TABS, but only those TABS contained within DiffAdd & DiffChange sections/regions.
What I tried:
syntax region TESTRGN start="TESTRGN_START" end="TESTRGN_END"
highlight TESTRGN ctermbg=lightgreen guibg=lightgreen
syntax match LeadingTabsInRegion display contained containedin=TESTRGN /^\( *\t\+\)\+/
highlight LeadingTabsInRegion ctermbg=darkred guibg=darkred
Above snippet highlights the leading TABS within TESTRGN & tabs in remaining file remain un-highlighted.
However, if I change TESTRGN to DiffAdd in the syntax match line, it does not work as I expected.
My understanding is that DiffAdd is not a region defined using syntax region ... & hence containedin=DiffAdd does not work.
So is there any method/work-around for doing what I am trying to do?
First, what's so bad about having the highlighting everywhere? The diff highlighting stands out well and therefore provides visible scope; couldn't you just ignore the highlighting elsewhere?
In Vim, syntax groups are defined and then linked to colors and attributes defined in highlight groups. The diff stuff uses the second part of that mechanism, but not the syntax part. Therefore, you unfortunately cannot refer to the diff regions within :syntax commands.
There's only a very ugly workaround for this: You have to determine the line numbers that have diff highlighting (via repeatedly stepping through the changes with the ]c motion, and/or using synID() to check for diff highlighting). With those line numbers, you can then define :syntax match commands with the special \%l atom that only matches certain lines. Of course, any addition / deletion of lines would invalidate your definitions, which would need to be frequently re-synchronized (triggered by :autocmd). That's a lot of effort vs. just ignoring the highlighting elsewhere.
Though you need to reset whenever the line was changed, this is just a tip for one of line number based ideas, you can get a list of all diff highlighted lines with:
let dl = filter(range(1, line('$')),
\'index([hlID("DiffChange"), hlID("DiffText"), hlID("DiffAdd")],
\diff_hlID(v:val, 1)) != -1')
And using this, it might be possible to set your TESTRGN with:
exec "syntax match TESTRGN /\\(" . join(map(dl, '"\\%" . v:val . "l"'), "\\|") . "\\).*/"
I want to write a syntax coloring script for a programming language I'm writing a compiler for, but to minimize the work required (as I barely know vimscript) I would like to find a coloring script that produces colors that are close enough to what I want to be able to just edit that script.
What is the best way to have Vim show me a specific code file and then apply every single different syntax coloring script it knows, so that I can determine which is closest? So far I've been using
:set syntax=<the next syntax script>
but is there anything easier, or less repetitive?
You can cycle through all your syntax scripts by applying the following steps:
1: Find all your installed syntax scripts and store them in a variable
:redir #a
:echo glob($VIMRUNTIME . '/syntax/*.vim')
" Hit G
" Hit Enter
:redir END
2: Open a new buffer in vim and paste your scripts from the register 'a' by typing in command mode:
"ap
3: This will output all your syntax scripts (excerpt from the first lines of my 1205 installed ones)
/usr/local/Cellar/macvim/7.4-72/MacVim.app/Contents/Resources/vim/runtime/syntax/2html.vim
/usr/local/Cellar/macvim/7.4-72/MacVim.app/Contents/Resources/vim/runtime/syntax/a2ps.vim
/usr/local/Cellar/macvim/7.4-72/MacVim.app/Contents/Resources/vim/runtime/syntax/a65.vim
/usr/local/Cellar/macvim/7.4-72/MacVim.app/Contents/Resources/vim/runtime/syntax/aap.vim
/usr/local/Cellar/macvim/7.4-72/MacVim.app/Contents/Resources/vim/runtime/syntax/abap.vim
4: Cut these by using Visual Block Mode, so that the result looks like this (again omitting ~1200 lines):
2html.vim
a2ps.vim
a65.vim
aap.vim
abap.vim
abaqus.vim
abc.vim
abel.vim
5: Now strip away the ".vim" ending by applying the following Regular Expression:
%s/.vim//g
Now they will look like this:
2html
a2ps
a65
aap
abap
abaqus
abc
abel
6: Save the result into a buffer. From there you can use this script to cycle through all of them:
v$h"*y:set syntax=^R*^Mdd
Or, in order to color all the open windows, use :windo set syntax=... instead of :set syntax=....
Explanation:
mark the first syntax name
v$h
yank/save the name under the register *
"y
set the syntax in command mode
:set syntax=
delete the last checked syntax name
dd
If you save this script in a macro, you can cycle through them using ##
Enjoy(;
I recommend using colorschemes (read more about them using ":h colo"). You can list all your installed color schemes by using this command:
:colorscheme <ctrl+d>
Those you can copy to a buffer and cycle through them. If you want to go the easy way, there is a script ready that provides that functionality: CycleColor, a script to cycle through (almost) all available colorschemes: https://github.com/vim-scripts/CycleColor
I'm coding C# in Vim and I want to be able to fold both
+---- 3 lines: void SomeFunction()-----------------------------------------------
As well as
+---- 42 lines: #region The Answer To Life---------------------------------------
However, foldmarker must be a literal string. I've been led to the idea of foldmethod=syntax, but this doesn't work out of the box in Vim 7.3.
Other than setting the fold method to manual and writing a script, how can I achieve this?
My Vim 7.3 runtime has a syntax/cs.vim file (from 14-Aug-2009) that supports syntax folding for #region. Syntax folding is nice; I'd advise against another foldmethod. I would contact the author of the syntax file and suggest the missing folding of functions as an enhancement; many other filetypes have this, and it seems to be common and helpful. (This can be made configurable for those who don't want one or the other.)
In the meantime, you can add the following to ~/.vim/after/syntax/cs.vim to enable folding of any curly braces blocks:
syn region csFold start="{" end="}" transparent fold
VIM: Is it possible to change the color of these symbols:
~!%^&*()-+=[]{},.<>?:/;
like Visual Studio does?
The C/C++ syntaxes are defined in syntax/c.vim and syntax/cpp.vim. If you're using Linux, the main syntax directory is in /usr/share/vimXX/, where XX is the version (e.g. mine are in vim72). I don't know about installation directories on other OSes, but I'm sure you can find it. I'd suggest making a copy of these and placing them in your user vim directory (for example, in Linux, $HOME/.vim/syntax/c.vim and so on). You can then add whatever you like.
The C++ syntax sources the C syntax, so any symbols you want highlighted in both should go in c.vim, and anything for C++ only should be in cpp.vim.
To get syntax highlighting for specific symbols, you'll need to use a syntax match statement, something like:
syn match cUserSpecialCharacter display "[~!%^&*()-+=[\]{},.<>?:;]"
syn match cUserSpecialCharacter display "/[^*/]"me=e-1
syn match cUserSpecialCharacter display "/$"
I called it cUserSpecialCharacter since cCharacter and cSpecialCharacter are already used. The second and third matches are a bit of a kludge to highlight '/' without it matching comment prefixes, which would then override the comment highlighting and break everything. The "display" option tells Vim that it doesn't need to look for this match if it's not going to be displayed - see :help syn-display for an explanation if you like!
Once you've defined a syntax match, you can link it to a highlight group, for example:
hi def link cUserSpecialCharacter cCharacter
This will put it in with the already defined cCharacter group, so it'll get whatever highlighting that gets - in this case, Character. You can see a nice list of highlight groups at the bottom of c.vim for examples. If you really want, you can also hardcode a highlight by doing something like:
hi cUserSpecialCharacter term=reverse ctermfg=15 ctermbg=1 guifg=#ffffff guibg=#800000
(Arbitrary example - my current highlighting for the Error group.) See :help hi for more information on this, or simply :hi to see the list of defined highlighting - plenty of examples. I'd recommend against doing this, though, since it won't change with color schemes.
Yes, you need to edit the C color theme in vimfiles/colors/c.vim I don't know all the theme options one can use, but I'm sure they are documented on http://vim.org/