[Tool] ChoiceScript Syntax Highlighting in Vim


#1

Continuing the discussion from Back Up Files From CS-IDE?:

I lied. I didn’t hold off. I wrote a vim syntax file for ChoiceScript. I’ve never messed with one before, so I’m sure it’s gross, but it works (for the commands I’ve put in so far).

I also made an indentation file for it, but it doesn’t work. No idea why, again, because I’ve never messed with that before.

Anyway, I thought it might help someone here, so if you want, have at it. If there’s any kind of demand, maybe I’ll make it an actual plugin.


#2

Thanks for doing this! I’ve found it really useful.

I found some ChoiceScript commands that weren’t included, so I’ve added them to the sections where they seemed to fit best.

The additional commands are

*allow_reuse
*hide_reuse
*rand
*ending
*achieve
*achievement
*image
*input_text
*input_number

The modified syntax file is up on GitHubt, and I’ve created a pull request if you’d like to merge the changes directly into yours. Thanks again!


#3

I’ve added some new features to the vi syntax file. I found a few more Choicescript commands that weren’t included, such as *check_achievements, so I’ve included them and reorganized the existing groupings a bit.

I also added support for bold, italic, and bold + italic text. Now when you use Choicescript’s [b][/b] and [i][/i] commands, vim will show the text as bold, italic, or both. Variables inside the formatting tags are still marked in the same color used in the rest of the document.

You can get the updated vim syntax file on Github. Happy vimming!


#4

Well, I’m a newbie with vim syntax files too, but here’s mine, along with my other vim-choicescript stuff:

https://github.com/Flurrywinde/vim-choicescript

For example, I made an indent file that seems to work, got folds to work, auto-detect the choicescript filetype, and auto-load some new vim commands that help when coding in choicescript.

I didn’t think choicescripters were using vim, so I was waiting until I learned how to package this as a plugin and make an easy-vim version. However, now that I know I’m not the only vim-choicescripter, I might as well put this out there now. Let me know what you think!


#5

I like what you’ve done here! Would you mind if I merge your commands into the file I’ve been sharing? (I’ll credit you at the top, of course.)


#6

Please do! And see if you can figure out how to fix it. For example, *fake_choices don’t do the indent right. I think *choice only does if there’s a *goto, etc. It works well enough, though, so I haven’t bothered looking into these things further.


#7

While, okay, I haven’t done anything with the indentation, I did add highlighting for the new conditional interpolation. That’s the stuff that looks like

@{((somevar = “this”) or (othervar = “that”)) first text|${variable}|last text}

The variables inside are highlighted in a different color, and the pipe symbol (|) is too, since omitting that pipe symbol has been a common error for me.

I also overrode some of the colors, since too many of the built-in categories had the same colors for my tastes.

Updated Vim syntax file for Choicescript


#8

I’ve added support for the *text_area Choicescript command, and a new region that matches parenthesized conditional expressions. In addition to recognizing the conditionals in expressions like

*if ((var > val) and not (othervar = "some text")

it will also change the color of the parenthesized expression in the conditional text interpolation, so in a line like

@{(var) something|something else|some other thing}

the conditional at the beginning will appear in a different color than the text in the second half

Updated Vim syntax file for Choicescript.