I have some Racket programms that begin with the specification of a dialect

#lang plai-typed

#| racket code goes here ... |#

When I open these files with Vim, filetype is set to plai-typed. That is a problem because it breaks syntax highlighting.

If I delete the line that contains #lang, then filetype is set to racket and syntax highlighting works as expected.

Why is Vim setting the filetype that way? How to stop that without deleting the line with #lang?

  • 1
    This behavior is coming from here. You can probably work around it by setting g:racket_hash_lang_dict in your vimrc (takes precedence over that one) that includes a plai-typed key mapping to racket. (I'd also copy the rest of the dict entries to keep the behavior for those #langs too in that case.) I see that @D.BenKnoble pushed the last commit to that file, so wondering if he'd like to expand on handling of #lang for Racket?
    – filbranden
    Commented Dec 13, 2021 at 20:36
  • 1
    Could also be using my version of the plugin github.com/benknoble/vim-racket My version supports better overrides, IIRC. The hash_lang_dict approach is correct. I'll have to elaborate more later, but if you use my fork you won't need to keep all the other entries as they get merged in.
    – D. Ben Knoble
    Commented Dec 13, 2021 at 23:50
  • 1
    thank you guys! that's correct, thanks for the workardound. If you answet the question I'll mark it as accepted
    – user37373
    Commented Dec 14, 2021 at 1:40
  • 1
    I've made some edits, but if you will please edit and mention the plugin you were using, that will improve the question
    – D. Ben Knoble
    Commented Dec 14, 2021 at 21:08

1 Answer 1


Alright, this is my fault :)

As I explain here:

This is at least partially my fault; I advocated for this on the basis that not all *rkt files are actually racket, and the racket syntax shouldn't try to highlight them all.

OTOH, br is now correctly mapped to racket, and it's trivial to add sicp/etc. (My fork adds, for example, info and info/setuptab, which it supports. My fork also supports the new jsond language, but it doesn't need extra configuration precisely because of the new mechanism.)

See g:racket_hash_lang_dict in ftdetect/racket.vim. It would be nicer to merge the user's config with the defaults, but I didn't do that yet as I haven't needed it.

Fortunately the global variable is extensible.

Depending on which version of the plugin you use:

  • for the wlangstroth fork, use
:let g:racket_hash_lang_dict = { 'plai-typed': 'racket', <all the default values here> }
  • for the benknoble (my) fork, use just
:let g:racket_hash_lang_dict = { 'plai-typed': 'racket' }

Since my fork supports merging the current value with defaults. My fork also has a few other tweaks and overridable variables, as well as general improvements. It also gets updated more often.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.