[Tool] ChoiceScript Syntax Highlighting in Vim

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 Likes

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!

2 Likes

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!

2 Likes

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!

2 Likes

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.)

1 Like

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.

1 Like

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

1 Like

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.

1 Like

@TracyCanfield I see you have updated your syntax file since I’ve been here last. Nice! I’m trying it out now, comparing it to mine. I didn’t see my folds code in it, so I’m going to see if it will still work in yours.

Anyway, I just stopped by, cuz I think this is the main Choicescript/Vim thread, and I wanted to announce that I added Ctags support for Choicescript in vim, which enables jumping to where variables, labels, and achievements are created and even a sidebar with all of them, sorted and categorized to refer to and/or jump to.

It will kinda look like this:

Everything still here at: https://github.com/Flurrywinde/vim-choicescript

1 Like

Well, my fold code breaks some things when added to your syntax file (e.g. bolditalics and italicsbold), so I added (stole :wink:) all the stuff you had that I didn’t, plus fixed some bugs in yours. (Basically, #, true, false, and parentheses in regular text are still highlighted.) So now mine does everything yours does (but the colors might be different), with bug fixes, and folding.

1 Like

Thanks a lot! This is very helpful!

A thank you from a newcomer to ChoiceScript. Good to know I am not the only Late Cretaceous dinosaur still using vim.
I had written my own syntax file but your collective efforts are much better :slight_smile: