Vim syntaxfile: Difference between revisions
From wikinotes
No edit summary |
No edit summary |
||
Line 8: | Line 8: | ||
|- | |- | ||
| <code>:h syn-region</code> || https://vimhelp.org/syntax.txt.html#%3Asyn-region | | <code>:h syn-region</code> || https://vimhelp.org/syntax.txt.html#%3Asyn-region | ||
|- | |||
| <code>:h syn-arguments</code> (ex. conceal, cchar, contained, ..) || https://vimhelp.org/syntax.txt.html#%3Asyn-arguments | |||
|- | |- | ||
|} | |} | ||
Line 23: | Line 25: | ||
= Example = | = Example = | ||
<blockquote> | <blockquote> | ||
{{ expand | |||
| <code>ftdetect/my_language.vim</code> | |||
| | |||
Register a filetype based on a file-extension | |||
<syntaxhighlight lang="vim"> | <syntaxhighlight lang="vim"> | ||
" ftdetect/ | " ftdetect/my_language.vim | ||
au BufRead,BufNewFile *.todo set filetype=todolist_simple | au BufRead,BufNewFile *.todo set filetype=todolist_simple | ||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | |||
{{ expand | |||
| <code>indent/my_language.vim</code> | |||
| | |||
Define the indent settings for the filetype | |||
<syntaxhighlight lang="vim"> | <syntaxhighlight lang="vim"> | ||
" indent/ | " indent/my_language.vim | ||
let b:did_indent = 1 | let b:did_indent = 1 | ||
Line 41: | Line 58: | ||
setlocal expandtab | setlocal expandtab | ||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | |||
{{ expand | |||
| <code>syntax/my_language.vim</code> | |||
| | |||
Define the syntax-highligting for the filetype | |||
<syntaxhighlight lang="vim"> | <syntaxhighlight lang="vim"> | ||
" syntax/ | " syntax/my_language.vim | ||
if exists( | " don't reload if already loaded | ||
if exists('b:my_language_syntax') | |||
finish | |||
endif | endif | ||
" Define marker colours (CLI/GUI) | " Define marker colours (CLI/GUI) | ||
let s:todo_colour = 'magenta' | let s:todo_colour = 'magenta' | ||
let s:gui_todo_colour = '#F57900' | let s:gui_todo_colour = '#F57900' | ||
" Define Regexes | " Define Regexes | ||
let s:todo_regex = '\(^\s*\)\@<=\*\([a-zA-Z]\)\@!' | let s:todo_regex = '\(^\s*\)\@<=\*\([a-zA-Z]\)\@!' | ||
" Define syntax for Regexes | " Define syntax for Regexes | ||
execute "syntax match | execute "syntax match my_language_todo '". s:todo_regex ."'" | ||
" Apply highlighting | " Apply highlighting | ||
execute ' highlight todolistsimple_todo ctermfg='. s:todo_colour .' guifg='. s:gui_todo_colour .' ctermbg=none cterm=bold gui=bold' | execute ' highlight todolistsimple_todo ctermfg='. s:todo_colour .' guifg='. s:gui_todo_colour .' ctermbg=none cterm=bold gui=bold' | ||
" mark file as loaded | |||
let b:my_language_syntax = 1 | |||
</syntaxhighlight> | |||
}} | |||
</blockquote><!-- Example --> | |||
= Basics = | |||
<blockquote> | |||
</blockquote><!-- Basics --> | |||
= Match Regions = | |||
<blockquote> | |||
<syntaxhighlight lang="vim"> | |||
syntax match | |||
\ MyCharacter | |||
\ /'.'/ | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- | </blockquote><!-- Match Regions --> |
Revision as of 15:12, 30 July 2023
Syntax for writing vim syntax-files.
Documentation
:h syn-match
https://vimhelp.org/syntax.txt.html#%3Asyn-match :h syn-region
https://vimhelp.org/syntax.txt.html#%3Asyn-region :h syn-arguments
(ex. conceal, cchar, contained, ..)https://vimhelp.org/syntax.txt.html#%3Asyn-arguments
Locations
${vim-or-plug}/syntax/${vim_filetype}.vim
syntax files
Example
ftdetect/my_language.vim
Register a filetype based on a file-extension" ftdetect/my_language.vim au BufRead,BufNewFile *.todo set filetype=todolist_simple
indent/my_language.vim
Define the indent settings for the filetype" indent/my_language.vim let b:did_indent = 1 setlocal autoindent setlocal indentexpr= setlocal tabstop=4 setlocal softtabstop=4 setlocal shiftwidth=4 setlocal expandtab
syntax/my_language.vim
Define the syntax-highligting for the filetype" syntax/my_language.vim " don't reload if already loaded if exists('b:my_language_syntax') finish endif " Define marker colours (CLI/GUI) let s:todo_colour = 'magenta' let s:gui_todo_colour = '#F57900' " Define Regexes let s:todo_regex = '\(^\s*\)\@<=\*\([a-zA-Z]\)\@!' " Define syntax for Regexes execute "syntax match my_language_todo '". s:todo_regex ."'" " Apply highlighting execute ' highlight todolistsimple_todo ctermfg='. s:todo_colour .' guifg='. s:gui_todo_colour .' ctermbg=none cterm=bold gui=bold' " mark file as loaded let b:my_language_syntax = 1
Basics
Match Regions
syntax match \ MyCharacter \ /'.'/