ed.vim (19093B)
1 " Vim syntax file 2 " Language: ed(1) 3 " Maintainer: Doug Kearns <dougkearns@gmail.com> 4 " Last Change: 2026 Aug 27 5 6 if exists("b:current_syntax") 7 finish 8 endif 9 let s:cpo_save = &cpo 10 set cpo&vim 11 12 syn match edLineStart 13 \ /^/ 14 \ skipwhite 15 \ nextgroup=@edAddress,edAddressSeparator,@edCommand 16 17 " Addresses {{{1 18 19 " TODO: Rename edAddress_Line, edAdress_Mark etc? 20 syn match edAddress contained 21 \ /[.$]\|\d\+\|'[a-z]/ 22 \ skipwhite 23 \ nextgroup=@edAddressModifier,edAddressSeparator,@edCommand 24 syn region edAddress_Pattern contained 25 \ matchgroup=Delimiter 26 \ start=+/+ 27 \ end=+/\|$+ 28 \ skipwhite 29 \ nextgroup=@edAddressModifier, 30 \ edAddressSeparator, 31 \ @edCommand, 32 \ edAddress_Pattern_Flag 33 \ contains=edRegex_SlashEscape, 34 \ edRegex_BackslashEscape, 35 \ edRegex_BracketExpression 36 syn region edAddress_Pattern contained 37 \ matchgroup=Delimiter 38 \ start=/?/ 39 \ end=/?\|$/ 40 \ skipwhite 41 \ nextgroup=@edAddressModifier, 42 \ edAddressSeparator, 43 \ @edCommand, 44 \ edAddress_Pattern_Flag 45 \ contains=edRegex_QuestionMarkEscape, 46 \ edRegex_BackslashEscape, 47 \ edRegex_BracketExpression 48 49 syn match edAddress_Pattern_Flag contained 50 \ +[/?]\@1<=I+ 51 \ skipwhite 52 \ nextgroup=@edAddressModifier,edAddressSeparator,@edCommand 53 54 syn match edRegex_BracketExpression contained 55 \ /\[\^\=\]\=\%(\[:.\{-}:\]\|\[\..\{-}\.\]\|\[=.\{-}=\]\|[^]]\)*\]/ 56 \ contains=NONE 57 \ transparent 58 syn match edRegex_SlashEscape contained 59 \ +\\/+ 60 \ contains=NONE 61 \ transparent 62 syn match edRegex_QuestionMarkEscape contained 63 \ /\\?/ 64 \ contains=NONE 65 \ transparent 66 syn match edRegex_BackslashEscape contained 67 \ /\\\\/ 68 \ contains=NONE 69 \ transparent 70 syn match edRegex_EscapeSequence contained 71 \ /\\./ 72 \ contains=NONE 73 \ transparent 74 75 76 syn cluster edAddress 77 \ contains=edAddress,edAddress_Pattern,edAddressModifier_Offset 78 79 syn match edAddressModifier_Offset contained 80 \ /[+-]\s*\%(\d\+\)\=/ 81 \ skipwhite 82 \ nextgroup=@edAddressModifier,edAddressSeparator,@edCommand 83 " BSD extension 84 syn match edAddressModifier_Offset contained 85 \ /\^\s*\%(\d\+\)\=/ 86 \ skipwhite 87 \ nextgroup=@edAddressModifier,edAddressSeparator,@edCommand 88 syn match edAddressModifier_Count contained 89 \ /\d\+/ 90 \ skipwhite 91 \ nextgroup=@edAddressModifier,edAddressSeparator,@edCommand 92 syn cluster edAddressModifier 93 \ contains=edAddressModifier_Offset,edAddressModifier_Count 94 95 syn match edAddressSeparator contained 96 \ /[,;]/ 97 \ skipwhite 98 \ nextgroup=@edAddress,edAddressSeparator,@edCommand 99 " BSD/GNU extension 100 syn match edAddressSeparator contained 101 \ /%/ 102 \ skipwhite 103 \ nextgroup=@edAddress,edAddressSeparator,@edCommand 104 105 " Commands {{{1 106 107 " Append Command {{{2 108 syn match edCommand_Append contained 109 \ /a/ 110 \ skipnl 111 \ nextgroup=@edCommandPrint_InputMode, 112 \ edArg_InputMode_Text, 113 \ edArg_InputMode_EndMarker, 114 \ edLineContinue_InputMode 115 116 syn match edArg_InputMode_EndMarker contained 117 \ /^\.\ze\%(\s*\\\)\=$/ 118 119 syn region edArg_InputMode_Text contained 120 \ start=/^\%(\.$\)\@!/ 121 "\ end=/^\.$/ 122 \ matchgroup=edArg_InputMode_EndMarker 123 "\ TODO: remove \\? 124 \ end=/^\.\ze\%(\s*\\\)\=$/ 125 \ fold 126 syn region edArg_InputMode_Text_Global contained 127 \ start=/^\%(\.$\)\@!/ 128 \ end=/\ze\\\@1<!\n/ 129 \ matchgroup=edArg_InputMode_EndMarker 130 \ end=/^\.\ze\%(\s*\\\)\=$/ 131 \ skipwhite 132 \ nextgroup=edLineContinue 133 \ contains=edLineContinue_InputMode_Text 134 \ fold 135 136 " Change Command {{{2 137 syn match edCommand_Change contained 138 \ /c/ 139 \ skipnl 140 \ nextgroup=@edCommandPrint_InputMode, 141 \ edArg_InputMode_Text, 142 \ edArg_InputMode_EndMarker, 143 \ edLineContinue_InputMode 144 145 " Delete Command {{{2 146 syn match edCommand_Delete contained 147 \ /d/ 148 \ nextgroup=@edCommandPrint 149 150 " TODO: maybe implement as a region so that the command list is contained? 151 " Global Command {{{2 152 syn match edCommand_Global contained 153 \ /g/ 154 \ nextgroup=edCommand_Global_Arg_Regexp 155 syn region edCommand_Global_Arg_Regexp contained 156 \ matchgroup=Delimiter 157 \ start=/\z([^\\ \n]\)/ 158 \ end=/\z1\|$/ 159 \ skipwhite 160 \ nextgroup=@edAddress, 161 \ edAddressSeparator, 162 \ @edCommand, 163 \ edCommand_Global_Arg_Regexp_Flag 164 \ contains=edRegex_EscapeSequence,edRegex_BracketExpression 165 166 " GNU extension 167 syn match edCommand_Global_Arg_Regexp_Flag contained 168 \ /[^\\ \n]\@1<=I/ 169 \ skipwhite 170 \ nextgroup=@edAddress,edAddressSeparator,@edCommand 171 172 syn match edLineContinue_InputMode contained 173 \ /\\$/ 174 \ skipnl 175 \ nextgroup=edArg_InputMode_Text_Global,edArg_InputMode_EndMarker 176 syn match edLineContinue_InputMode_Text contained /\\$/ 177 syn match edLineContinue /\\$/ skipnl nextgroup=edLineStart 178 179 " Interactive Global Command {{{2 180 syn match edCommand_InteractiveGlobal contained 181 \ /G/ 182 \ nextgroup=edCommand_InteractiveGlobal_Arg_Regexp 183 syn region edCommand_InteractiveGlobal_Arg_Regexp contained 184 \ matchgroup=Delimiter 185 \ start=/\z([^\\ \n]\)/ 186 \ end=/\z1\|$/ 187 \ nextgroup=edCommand_InteractiveGlobal_Arg_Regexp_Flag 188 \ contains=edRegex_EscapeSequence,edRegex_BracketExpression 189 190 " GNU extension 191 syn match edCommand_InteractiveGlobal_Arg_Regexp_Flag contained 192 \ /[^\\ \n]\@1<=I/ 193 194 syn match edCommand_Repeat contained 195 \ /&/ 196 197 " Insert Command {{{2 198 syn match edCommand_Insert contained 199 \ /i/ 200 \ skipnl 201 \ nextgroup=@edCommandPrint_InputMode, 202 \ edArg_InputMode_Text, 203 \ edArg_InputMode_EndMarker, 204 \ edLineContinue_InputMode 205 206 " Join Command {{{2 207 syn match edCommand_Join contained 208 \ /j/ 209 \ nextgroup=@edCommandPrint 210 211 " Mark Command {{{2 212 syn match edCommand_Mark contained 213 \ /k/ 214 \ nextgroup=edCommand_Mark_Arg_Name 215 syn match edCommand_Mark_Arg_Name contained 216 \ /[a-z]/ 217 \ nextgroup=@edCommandPrint 218 219 " List Command {{{2 220 syn match edCommand_List contained 221 \ /l/ 222 \ nextgroup=@edCommandPrint 223 224 syn match edCommand_List_InputMode contained 225 \ /^\@1<!l/ 226 \ skipnl 227 \ nextgroup=@edCommandPrint_InputMode, 228 \ edArg_InputMode_Text, 229 \ edArg_InputMode_EndMarker, 230 \ edLineContinue_InputMode 231 232 " Move Command {{{2 233 syn match edCommand_Move contained 234 \ /m/ 235 "\ GNU extension 236 \ skipwhite 237 \ nextgroup=@edAddress,edAddressSeparator,@edCommandPrint 238 239 " Number Command {{{2 240 syn match edCommand_Number contained 241 \ /n/ 242 \ nextgroup=@edCommandPrint 243 244 syn match edCommand_Number_InputMode contained 245 \ /^\@1<!n/ 246 \ skipnl 247 \ nextgroup=@edCommandPrint_InputMode, 248 \ edArg_InputMode_Text, 249 \ edArg_InputMode_EndMarker, 250 \ edLineContinue_InputMode 251 252 " Print Command {{{2 253 syn match edCommand_Print contained 254 \ /p/ 255 \ nextgroup=@edCommandPrint 256 257 syn match edCommand_Print_InputMode contained 258 \ /^\@1<!p/ 259 \ skipnl 260 \ nextgroup=@edCommandPrint_InputMode, 261 \ edArg_InputMode_Text, 262 \ edArg_InputMode_EndMarker, 263 \ edLineContinue_InputMode 264 265 " Read Command {{{2 266 syn match edCommand_Read contained 267 \ /r\>/ 268 \ skipwhite 269 \ nextgroup=edArg_File,edCommand_ShellEscape 270 271 " Substitute Command {{{2 272 syn match edCommand_Substitute contained 273 \ /s/ 274 \ nextgroup=edCommand_Substitute_Arg_Regexp 275 syn region edCommand_Substitute_Arg_Regexp contained 276 \ matchgroup=Delimiter 277 \ start=/\z([^\\ \n]\)/ 278 "\ /$/ so we don't run to EOF when editing 279 \ end=/\ze\z1\|$/ 280 \ nextgroup=edCommand_Substitute_Arg_Replacement 281 \ contains=edRegex_EscapeSequence,edRegex_BracketExpression 282 syn region edCommand_Substitute_Arg_Replacement contained 283 \ matchgroup=Delimiter 284 \ start=/\z(.\)/ 285 \ skip=/\\$/ 286 \ end=/\z1\|$/ 287 \ nextgroup=edCommand_Substitute_Arg_Flag,edCommand_Substitute_Arg_Count 288 \ contains=edCommand_Substitute_Arg_Replacement_Escape, 289 \ edCommand_Substitute_Arg_Replacement_Newline, 290 \ edCommand_Substitute_Arg_Replacement_Match 291 292 syn region edCommand_Substitute_Arg_Replacement contained 293 \ matchgroup=Delimiter 294 \ start=/\z(.\)%\@=/ 295 \ end=/\%(\z1%\)\@<=\%(\z1\|$\)/ 296 \ nextgroup=edCommand_Substitute_Arg_Flag,edCommand_Substitute_Arg_Count 297 \ contains=edCommand_Substitute_Arg_Replacement_Repeat 298 \ oneline 299 300 syn match edCommand_Substitute_Arg_Replacement_Escape contained /\\./ 301 syn match edCommand_Substitute_Arg_Replacement_Newline contained /\\$/ 302 syn match edCommand_Substitute_Arg_Replacement_Match contained /&/ 303 syn match edCommand_Substitute_Arg_Replacement_Repeat contained /%/ 304 305 syn match edCommand_Substitute_Arg_Flag contained 306 \ /g/ 307 \ nextgroup=edCommand_Substitute_Arg_Flag,edCommand_Substitute_Arg_Count 308 " GNU extension 309 syn match edCommand_Substitute_Arg_Flag contained 310 \ /[iI]/ 311 \ nextgroup=edCommand_Substitute_Arg_Flag,edCommand_Substitute_Arg_Count 312 313 syn match edCommand_Substitute_Arg_Count contained 314 \ /\d\+/ 315 \ nextgroup=edCommand_Substitute_Arg_Flag 316 317 syn match edCommand_Substitute_Arg_Flag contained 318 \ /[lnp]/ 319 \ skipnl 320 \ nextgroup=edCommand_Substitute_Arg_Flag,edCommand_Substitute_Arg_Count 321 322 " repeat last s command 323 " BSD/GNU extension 324 325 syn match edCommand_Substitute contained 326 \ /s\%(\%([gpr]\|\d\+\)\{1,4}\&\%(.*\([gpr]\).*\1\)\@!\&\%(.*\d\D\+\d\)\@!.*\)\>/ 327 \ contains=edCommand_Substitute_Arg_Flag,edCommand_Substitute_Arg_Count 328 329 syn match edCommand_Substitute_Arg_Flag contained 330 \ /r/ 331 \ nextgroup=edCommand_Substitute_Arg_Flag,edCommand_Substitute_Arg_Count 332 333 " Copy Command {{{2 334 syn match edCommand_Copy contained 335 \ /t/ 336 "\ GNU extension 337 \ skipwhite 338 \ nextgroup=@edAddress,edAddressSeparator,@edCommandPrint 339 340 " TODO: maybe implement as a region so that the command list is contained? 341 " Global Not-Matched Command {{{2 342 syn match edCommand_GlobalNotMatched contained 343 \ /v/ 344 \ nextgroup=edCommand_GlobalNotMatched_Arg_Regexp 345 syn region edCommand_GlobalNotMatched_Arg_Regexp contained 346 \ matchgroup=Delimiter 347 \ start=/\z([^\\ \n]\)/ 348 \ end=/\z1\|$/ 349 \ skipwhite 350 \ nextgroup=@edAddress, 351 \ edAddressSeparator, 352 \ @edCommand, 353 \ edCommand_GlobalNotMatched_Arg_Regexp_Flag 354 \ contains=edRegex_EscapeSequence,edRegex_BracketExpression 355 356 " GNU extension 357 syn match edCommand_GlobalNotMatched_Arg_Regexp_Flag contained 358 \ /[^\\ \n]\@1<=I/ 359 \ skipwhite 360 \ nextgroup=@edAddress,edAddressSeparator,@edCommand 361 362 " Interactive Global Not-Matched Command {{{2 363 syn match edCommand_InteractiveGlobalNotMatched contained 364 \ /V/ 365 \ nextgroup=edCommand_InteractiveGlobalNotMatched_Arg_Regexp 366 syn region edCommand_InteractiveGlobalNotMatched_Arg_Regexp contained 367 \ matchgroup=Delimiter 368 \ start=/\z([^\\ \n]\)/ 369 \ end=/\z1\|$/ 370 \ nextgroup=edCommand_InteractiveGlobalNotMatched_Arg_Regexp_Flag 371 \ contains=edRegex_EscapeSequence,edRegex_BracketExpression 372 373 " GNU extension 374 syn match edCommand_InteractiveGlobalNotMatched_Arg_Regexp_Flag contained 375 \ /[^\\ \n]\@1<=I/ 376 377 " Write Command {{{2 378 syn match edCommand_Write contained 379 \ /w\>/ 380 \ skipwhite 381 \ nextgroup=edArg_File,edCommand_ShellEscape 382 383 " Write Append Command {{{2 384 " BSD/GNU extension 385 syn match edCommand_WriteAppend contained 386 \ /W\>/ 387 \ skipwhite 388 \ nextgroup=edArg_File,edCommand_ShellEscape 389 390 " Write Quit Command {{{2 391 " BSD/GNU extension 392 syn match edCommand_WriteQuit contained 393 \ /wq\>/ 394 \ skipwhite 395 \ nextgroup=edArg_File,edCommand_ShellEscape 396 397 " Paste Cut Buffer Command {{{2 398 " GNU extension 399 syn match edCommand_Paste contained 400 \ /x/ 401 \ nextgroup=@edCommandPrint 402 403 " Yank Cut Buffer Command {{{2 404 " GNU extension 405 syn match edCommand_Yank contained 406 \ /y/ 407 \ nextgroup=@edCommandPrint 408 409 " Scroll Command {{{2 410 " BSD/GNU extension 411 syn match edCommand_Scroll contained 412 \ /z/ 413 \ nextgroup=edCommand_Scroll_Arg_Count,@edCommandPrint 414 syn match edCommand_Scroll_Arg_Count contained 415 \ /\d\+/ 416 \ nextgroup=@edCommandPrint 417 418 " Line Number Command {{{2 419 syn match edCommand_LineNumber contained 420 \ /=/ 421 \ nextgroup=@edCommandPrint 422 " }}} 423 424 " no address prefix commands 425 426 " Edit Command {{{2 427 syn match edCommand_Edit contained 428 \ /\<e\>/ 429 \ skipwhite 430 \ nextgroup=edArg_File,edCommand_ShellEscape 431 432 " Edit Without Checking Command {{{2 433 syn match edCommand_EditWithoutChecking contained 434 \ /\<E\>/ 435 \ skipwhite 436 \ nextgroup=edArg_File,edCommand_ShellEscape 437 438 " Filename Command {{{2 439 syn match edCommand_Filename contained 440 \ /\<f\>/ 441 \ skipwhite 442 \ nextgroup=edArg_File 443 444 " Help Command {{{2 445 syn match edCommand_Help contained 446 \ /\<h/ 447 \ nextgroup=@edCommandPrint 448 449 " Help-Mode Command {{{2 450 syn match edCommand_HelpMode contained 451 \ /\<H/ 452 \ nextgroup=@edCommandPrint 453 454 " Prompt Command {{{2 455 syn match edCommand_Prompt contained 456 \ /\<P/ 457 \ nextgroup=@edCommandPrint 458 459 " Quit Command {{{2 460 syn match edCommand_Quit contained 461 \ /\<q\>/ 462 463 " Quit Without Checking Command {{{2 464 syn match edCommand_QuitWithoutChecking contained 465 \ /\<Q\>/ 466 467 " Undo Command {{{2 468 syn match edCommand_Undo contained 469 \ /\<u/ 470 \ nextgroup=@edCommandPrint 471 472 " Shell Escape Command {{{2 473 syn match edCommand_ShellEscape contained 474 \ /!/ 475 \ skipwhite 476 \ nextgroup=edCommand_ShellEscape_Arg_Command, 477 \ edCommand_ShellEscape_Arg_Previous 478 syn match edCommand_ShellEscape_Arg_Command contained 479 \ /\S.*$/ 480 \ contains=edCommand_ShellEscape_Arg_Command_Filename, 481 \ edCommand_ShellEscape_Arg_Command_FilenameEscape, 482 \ edCommand_ShellEscape_Arg_Command_BackslashEscape 483 484 syn match edCommand_ShellEscape_Arg_Command_Filename contained 485 \ /%/ 486 487 syn match edCommand_ShellEscape_Arg_Command_FilenameEscape contained /\\%/ 488 syn match edCommand_ShellEscape_Arg_Command_BackslashEscape contained /\\\\/ 489 490 syn match edCommand_ShellEscape_Arg_Previous contained 491 \ /!/ 492 \ skipwhite 493 \ nextgroup=edCommand_ShellEscape_Arg_Command 494 495 " Comment Command {{{2 496 " GNU extension 497 syn match edCommand_Comment contained 498 \ /#.*/ 499 " }}} 500 501 syn cluster edCommand contains=edCommand_\a\+ 502 503 " Command Args {{{2 504 syn match edArg_File contained /!\@!\S.*$/ 505 506 " Command Suffixes {{{1 507 syn cluster edCommandPrint 508 \ contains=edCommand_List,edCommand_Number,edCommand_Print 509 syn cluster edCommandPrint_InputMode 510 \ contains=edCommand_List_InputMode, 511 \ edCommand_Number_InputMode, 512 \ edCommand_Print_InputMode 513 514 " Syncing {{{1 515 516 syn sync fromstart 517 518 " Default Highlighting {{{1 519 520 " addresses 521 522 hi def link edAddress Constant 523 hi def link edAddressModifier_Offset Special 524 hi def link edAddressModifier_Count Special 525 hi def link edAddress_Pattern Regexp 526 hi def link edAddress_Pattern_Flag Special 527 528 " commands (addresses) 529 530 hi def link edCommand Statement 531 532 hi def link edCommand_Append Statement 533 hi def link edCommand_Change Statement 534 hi def link edCommand_Copy Statement 535 hi def link edCommand_Delete Statement 536 hi def link edCommand_GlobalNotMatched Statement 537 hi def link edCommand_Global Statement 538 hi def link edCommand_Insert Statement 539 hi def link edCommand_InteractiveGlobalNotMatched Statement 540 hi def link edCommand_InteractiveGlobal Statement 541 hi def link edCommand_Join Statement 542 hi def link edCommand_LineNumber Statement 543 hi def link edCommand_List Statement 544 hi def link edCommand_List_InputMode edCommand_List 545 hi def link edCommand_Mark Statement 546 hi def link edCommand_Move Statement 547 hi def link edCommand_Number Statement 548 hi def link edCommand_Number_InputMode edCommand_Number 549 hi def link edCommand_Paste Statement 550 hi def link edCommand_Print Statement 551 hi def link edCommand_Print_InputMode edCommand_Print 552 hi def link edCommand_Read Statement 553 hi def link edCommand_Repeat Statement 554 hi def link edCommand_Scroll Statement 555 hi def link edCommand_Substitute Statement 556 hi def link edCommand_WriteAppend Statement 557 hi def link edCommand_WriteQuit Statement 558 hi def link edCommand_Write Statement 559 hi def link edCommand_Yank Statement 560 561 " commands (no addresses) 562 563 hi def link edCommand_Edit Statement 564 hi def link edCommand_EditWithoutChecking Statement 565 hi def link edCommand_Filename Statement 566 hi def link edCommand_HelpMode Statement 567 hi def link edCommand_Help Statement 568 hi def link edCommand_Prompt Statement 569 hi def link edCommand_Quit Statement 570 hi def link edCommand_QuitWithoutChecking Statement 571 hi def link edCommand_ShellEscape Statement 572 hi def link edCommand_Undo Statement 573 574 hi def link edCommand_Comment Comment 575 576 " command args 577 578 hi def link edArg_InputMode_Text Normal 579 hi def link edArg_InputMode_Text_Global edArg_InputMode_Text 580 hi def link edArg_InputMode_EndMarker edCommand 581 582 hi def link edCommand_Mark_Arg_Name Constant 583 584 hi def link edCommand_Scroll_Arg_Count Number 585 586 hi def link edCommand_ShellEscape_Arg_Command_Filename Special 587 hi def link edCommand_ShellEscape_Arg_Command_FilenameEscape Special 588 hi def link edCommand_ShellEscape_Arg_Command_BackslashEscape Special 589 hi def link edCommand_ShellEscape_Arg_Previous Constant 590 591 hi def link edCommand_Substitute_Arg_Regexp Regexp 592 hi def link edCommand_Substitute_Arg_Replacement_Escape Special 593 hi def link edCommand_Substitute_Arg_Replacement_Newline Special 594 hi def link edCommand_Substitute_Arg_Replacement_Match Special 595 hi def link edCommand_Substitute_Arg_Replacement_Repeat Special 596 hi def link edCommand_Substitute_Arg_Flag Special 597 hi def link edCommand_Substitute_Arg_Count Special 598 599 hi def link edCommand_Global_Arg_Regexp Regexp 600 hi def link edCommand_Global_Arg_Regexp_Flag Special 601 hi def link edCommand_InteractiveGlobal_Arg_Regexp Regexp 602 hi def link edCommand_InteractiveGlobal_Arg_Regexp_Flag Special 603 hi def link edCommand_GlobalNotMatched_Arg_Regexp Regexp 604 hi def link edCommand_GlobalNotMatched_Arg_Regexp_Flag Special 605 hi def link edCommand_InteractiveGlobalNotMatched_Arg_Regexp Regexp 606 hi def link edCommand_InteractiveGlobalNotMatched_Arg_Regexp_Flag Special 607 608 " line continuation 609 610 hi def link edLineContinue Delimiter 611 hi def link edLineContinue_InputMode edLineContinue 612 hi def link edLineContinue_InputMode_Text edLineContinue 613 614 615 " }}} 616 617 let b:current_syntax = "ed" 618 619 let &cpo = s:cpo_save 620 unlet! s:cpo_save 621 622 " vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker: