Custom source highlighting for asciidoctor - asciidoctor

I am writing an asciidoc document and want to do syntax highlighting for "code" that is not known to the asciidoc highlighter.
For example I want to highlight the output of git status -sb
## main...origin/main
?? test.txt
For all I want I can imagine simple rules (for example regex).
Is there a simple way to extend the asciidoctor source code highlighter for custom syntax?

Related

Quick access to recurrent searches in Sublime Text

I have a regex expression that I use regularly to find specific lines in my codebase.
Let's say the expression is
\s*<search keyword> = myClass(.*)
with <search keyword> being the part of the regex that changes depending of the search.
How can I make entering such a search as fast as possible in ST3?
I tried using snippets that at first sight seem to fill my need as they enable to set the location where the text editing will be resumed, so I could just type <snippet alias><TAB><search keyword> in Find: field to trigger the search.
Alas no, snippets are disabled in search fields (only accessible in main text window).
You can use snippets in search bar, for example:
<snippet>
<content><![CDATA[
\s*$1 = myClass(.*)
]]></content>
<tabTrigger>search</tabTrigger>
<description>Search snippet</description>
</snippet>
BUT you can only expand them with CTRL+Space. Tab key for snippet expansion does not work in search field.
Btw: This works for me in Sublime Text 2. But it should work in Sublime Text 3 too

Adding syntax highlighting for latex plugin in vim

I am using a package called outlines for LaTeX. It adds commands such as \1 \2 \3 etc.
They are not highlighted by default in vim. So, I created a file called tex.vim in my .vimrc/syntax folder, and put this in the file:
:syn match outline /\\[1-9]/
hi link outline Label
This works only at the top level, not within a block. In other words, it works before my \begin{document}, but not between \begin{document} and \end{document}.
This is pretty much useless. How can I get vim to recognize the syntax, regardless of where it appears in the document?
You need to find the syntax group or cluster defined by the Tex syntax, and use contained containedin=..., but in your case, there is already a syntax group for statements, it's just that it doesn't include numbers. Therefore, you can just piggyback on the existing group and only add matching for numbers:
:syn match texStatement /\\\d/

How to selectively apply syntax highlight

I'm writing a tutorial/book with Vim, and I'd like to turn off the syntax highlighting for a block of text (the normal text of the book) and reactivate it for the code examples.
I have Googled to no end, but I cannot find a simple solution. Am I missing something? Or is this not achievable in Vim?
I have written the SyntaxRange plugin for that (my main use case is highlighting patches inside emails as with the "diff" syntax). With it, you can :[range]SyntaxIgnore or :[range]SyntaxInclude {filetype} certain sections of a buffer, or, when the sections start and end with certain markers, define dynamic sections that adapt when the number of lines change.
You can create a syntax file for your book.
For example, you can create a script: ~/.vim/syntax/tutor.vim
"
" tutor.vim -- syntax file for my book/tutor
"
syn include #PY $VIMRUNTIME/syntax/python.vim
syn region pyBlock start="{{{" end="}}}" contains=#PY
This is a sample file:
# File: intro.txt
# Date: 2012-08-19
blah, blah ...
So, I will show you some code:
{{{
def hello():
print "world"
}}}
# vim: set syn=tutor :
Thinking tangentially...
How about using something like restructured text or markdown within Vim and render on github. This gives you version management for free. You can have code-blocks.

vim search by syntax-highlighting type

I'm adding i18n to an existing project (web application). This involves replacing every bit of static text with calls to an i18n library. It would be convenient to be able to search for this text rather than rely on syntax highlighting to identify it visually.
In vim, is it possible to search within a file for occurrences of a certain highlighting type?
Something like:
/[%type=Boolean]
Sub 'Boolean' with 'Comment', 'htmlTag', or any group defined in your syntax highlighting file.
This plugin will do it for you
Take a look at the answer I gave here:
Vim search in C/C++ code lines
I think my :SearchInside command will do what you want.

How to syntax highlight fragments of code in one language embedded in the source code in another language in Vim?

I have a custom XML file format which can contain blocks of code within certain tags.
For example:
<Root>
<Sql> select * from foo </Sql>
<MoreJunk> ... </MoreJunk>
<Python><![CDATA[
def Bar(*args):
return False
]]></Python>
</Root>
How can I get Vim to use SQL syntax highlighting for the text inside <Sql> tags and use Python higlighting for text inside <Python> tags?
I know Vim can already do this because it correctly highlights Javascript inside HTML files.
I tried inspecting the HTML syntax file but couldn’t figure it out.
For your XML with python example you would have to do something like this:
runtime! syntax/xml.vim
unlet b:current_syntax
syntax include #Python syntax/python.vim
syntax region pythonCode start=+<Python>+ keepend end=+/</Python>+ contains=#Python
These lines will include the XML syntax and the python syntax, and the specify a python region where VIM will use the python syntax instead of the XML syntax...
Of course, all this is well documented in VIM. See :he :syn-include on how to include syntax files.
This document describes how to write your own syntax highlighting. You should probably be able to figure out how the HTML-syntax highlighting works with javascript, with that as a reference.

Resources