neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

skhd.vim (5433B)


      1 " Vim syntax file
      2 " Language:	skhd configuration file
      3 " Maintainer:	Kiyoon Kim <https://github.com/kiyoon>
      4 " Last Change:	2025 Jan 22
      5 
      6 if exists("b:current_syntax")
      7  finish
      8 endif
      9 
     10 " Comments: whole line from '#'
     11 syn match skhdComment /^\s*#.*/
     12 
     13 " Modifiers (shift, ctrl, alt, cmd, fn)
     14 syn keyword skhdModifier
     15      \ alt lalt ralt
     16      \ shift lshift rshift
     17      \ cmd lcmd rcmd
     18      \ ctrl lctrl rctrl
     19      \ fn hyper meh
     20      \ option super
     21 " highlight the '+' and '-' and ':' separators
     22 syn match skhdOperator /->/
     23 syn match skhdOperator /[+:\-;<>,\[\]@~]/
     24 
     25 " Hex keycode form: 0x3C etc
     26 syn match skhdKeycode /\v0x[0-9A-Fa-f]+/
     27 
     28 " Keys (a–z, digits, function‐keys, arrows…)
     29 syn keyword skhdKey
     30      \ return tab space backspace escape delete
     31      \ home end pageup pagedown insert
     32      \ left right up down
     33      \ sound_up sound_down mute play previous next rewind fast
     34      \ brightness_up brightness_down illumination_up illumination_down
     35 syn match skhdKey /\vf([1-9]|1[0-9]|20)\>/
     36 syn match skhdKey /\v\<[A-Za-z0-9]\>/
     37 
     38 " The yabai command and its subcommands
     39 syn match skhdCommand /\<yabai\>\|\<open\>/
     40 syn match skhdSubCmd   /\<window\>\|\<space\>\|\<display\>/
     41 
     42 " ───────────────────────────────────────────────────────────────────
     43 "  Treat anything after a single “:” (not double‑colon) as bash
     44 " ───────────────────────────────────────────────────────────────────
     45 " load Vim’s built‑in shell rules
     46 syntax include @bash syntax/bash.vim
     47 
     48 " After `:` (not `::`) is a bash command, but not when it is preceded by a `\`
     49 syn region skhdBash
     50      \ matchgroup=skhdOperator
     51      \ start=/\v(^|[^:])\zs:\s*/
     52      \ end=/\v\s*$\ze/
     53      \ skip=/\v\\\s*$/
     54      \ keepend
     55      \ contains=@bash
     56 
     57 " ────────────────────────────────────────────────────────────────
     58 "  Key‑map group definitions and switches
     59 " ────────────────────────────────────────────────────────────────
     60 " In skhd, you can define groups and assign hotkeys to them as follows:
     61 " 1. Group‑definition lines that start with :: <group>
     62 " 2. Switch operator (<)
     63 " 3. Target group names after the ;
     64 
     65 " Lines like `:: default` or `:: passthrough`
     66 "   match the whole thing as a GroupDef, but capture the group name
     67 syn match   skhdGroupDef    /^::\s*\w\+/
     68 syn match   skhdGroupName   /::\s*\zs\w\+/
     69 
     70 " The `<` switch token in lines like
     71 "   passthrough < cmd + shift + alt - b ; default
     72 syn match   skhdSwitch      /<\s*/
     73 
     74 " The target (or “fall‑through”) group after the semicolon
     75 "   ... ; default
     76 syn match   skhdTargetGroup /;\s*\zs\w\+/
     77 
     78 
     79 " ------------------------------------------------------------
     80 " Application-specific bindings block: <keysym> [ ... ]
     81 " ------------------------------------------------------------
     82 
     83 " The whole block. This avoids grabbing .blacklist by requiring the line be just '[' at end.
     84 syn region skhdProcMapBlock
     85      \ matchgroup=skhdProcMapDelim
     86      \ start=/\v\[\s*$/
     87      \ end=/^\s*\]\s*$/
     88      \ keepend
     89      \ transparent
     90      \ contains=skhdProcMapApp,skhdProcMapWildcard,skhdProcMapUnbind,skhdOperator,skhdComment,skhdBash,skhdString
     91 
     92 " App name on the left side:  "Google Chrome" :
     93 syn match skhdProcMapApp /^\s*\zs"[^"]*"\ze\s*:\s*/ contained
     94 
     95 " Wildcard entry:  * :
     96 syn match skhdProcMapWildcard /^\s*\zs\*\ze\s*:\s*/ contained
     97 
     98 " Unbind operator on the right side:  "App" ~   or   * ~
     99 syn match skhdProcMapUnbind /\v^\s*(\"[^"]*\"|\*)\s*\zs\~\ze\s*$/ contained
    100 
    101 syn keyword skhdDirective .load .blacklist
    102 syn match skhdLoadLine /^\s*\.load\>\s\+/ contains=skhdDirective
    103 
    104 syn region skhdBlacklistBlock
    105      \ start=/^\s*\.blacklist\>\s*\[\s*$/
    106      \ end=/^\s*\]\s*$/
    107      \ keepend
    108      \ contains=skhdDirective,skhdComment,skhdString
    109 
    110 syn region skhdString start=/"/ skip=/\\"/ end=/"/
    111 
    112 " ────────────────────────────────────────────────────────────────
    113 "  Linking to standard Vim highlight groups
    114 " ────────────────────────────────────────────────────────────────
    115 hi def link skhdComment    Comment
    116 hi def link skhdHeadline   Title
    117 hi def link skhdModifier   Keyword
    118 hi def link skhdOperator   Operator
    119 hi def link skhdWildcard     Special
    120 hi def link skhdKey        Identifier
    121 hi def link skhdKeycode      Number
    122 hi def link skhdCommand    Function
    123 hi def link skhdSubCmd     Statement
    124 hi def link skhdGroupDef      Label
    125 hi def link skhdGroupName     Identifier
    126 hi def link skhdSwitch        Operator
    127 hi def link skhdTargetGroup   Type
    128 hi def link skhdString String
    129 
    130 hi def link skhdProcMapDelim   Operator
    131 hi def link skhdProcMapApp     Type
    132 hi def link skhdProcMapWildcard Special
    133 hi def link skhdProcMapUnbind  Special
    134 
    135 hi def link skhdDirective PreProc
    136 
    137 let b:current_syntax = "skhd"