On this page:
24.3.1 Enhanced Racket Support
24.3.2 Indentation
24.3.3 Highlighting
24.3.4 Structured Editing
24.3.5 REPLs
24.3.6 Scribble
24.3.7 Miscellaneous
24.3.8 Older Versions of Vim

24.3 Vim🔗

Many distributions of Vim ship with support for Scheme, which will mostly work for Racket. Vim also ships with some special support for Racket.

The racket filetype comes with
  • syntax highlighting

  • custom indentation for Racket forms

  • and other support including comments and raco fmt

There is also support for several raco commands in the form of builtin compiler plugins; see :help compiler for more information.

For information about older Vim versions, see Older Versions of Vim.

24.3.1 Enhanced Racket Support🔗

Vim will detect your Racket files as Scheme out of the box. To get the additional features of the Racket filetype, consider installing the vim-racket plugin from benknoble/vim-racket. It enables auto-detection of Racket files on top of enhanced indentation and syntax highlighting. Vim’s default support comes from a subset of this plugin; installing it yourself provides additional features.

The vim-racket plugin detects the filetype option based on the #lang line. For example:

The vim-racket plugin comes with configuration for Racket and some other standard Racket languages.

Many Racket languages still need syntax and indent support. If you create Vim support for other Racket languages, please consider contributing them to benknoble/vim-racket so other Vim users will benefit.

24.3.2 Indentation🔗

If you use Enhanced Racket Support and Vim version 9 or greater, improved indentation for the racket filetype is configured out of the box.

Otherwise, you can manually enable indentation for Racket by setting both the lisp and autoindent options in Vim. You will want to customize the buffer-local lispwords option to control how special forms are indented. See :help lispwords. However, using lispwords for indentation can be limited and may not be as complete as what you can get in Emacs. You can also use Dorai Sitaram’s scmindent for better indentation of Racket code. The instructions on how to use the indenter are available on the website.

24.3.3 Highlighting🔗

Syntax highlighting for Scheme and Racket is shipped with Vim on many platforms. You will want to use the racket filetype for the best syntax experience; see Enhanced Racket Support for enhanced syntax highlighting for Racket languages.

The Rainbow Parenthesis script for Vim can be useful for more visible parenthesis matching.

24.3.4 Structured Editing🔗

The Slimv plugin has a paredit mode that works like paredit in Emacs. However, the plugin is not aware of Racket. You can either set Vim to treat Racket as Scheme files or you can modify the paredit script to load on ".rkt" files.

For a more Vim-like set of key-mappings, pair either of

The benknoble/vim-sexp fork is slightly more modern vimscript.

with tpope/vim-sexp-mappings-for-regular-people. The experience is on par with paredit, but more comfortable for the fingers.

24.3.5 REPLs🔗

There are many general-purpose Vim + REPL plugins out there. Here are a few that support Racket out of the box:

24.3.6 Scribble🔗

Vim support for writing scribble documents is provided by benknoble/scribble.vim.

24.3.7 Miscellaneous🔗

If you are installing many Vim plugins (not necessary specific to Racket), we recommend using a plugin that will make loading other plugins easier. There are many plugin managers.

Pathogen is one plugin that does this; using it, you can install new plugins by extracting them to subdirectories in the "bundle" folder of your personal Vim files ("~/.vim" on Unix, "$HOME/vimfiles" on MS-Windows).

With newer Vim versions, you can use the package system (:help packages).

One relatively up-to-date reference on the various managers is What are the differences between the vim plugin managers?. The same site, Vi & Vim is a great place to get help from Vimmers.

24.3.8 Older Versions of Vim🔗

As of Version 9.0.0336, Vim ships with runtime files from Enhanced Racket Support, but these exclude filetype detection for the racket filetype. If you are using this version or versions newer than this you probably want to tweak the suggestions in this document to use the racket filetype instead of scheme. You should also consider installing the plugin yourself to get the latest changes, since Ben is slow to sync changes upstream to Vim and since the plugin contains improved filetype detection.

As of version 7.3.518, Vim detects files with the extension .rkt as having the scheme filetype. Version 8.2.3368 added support for .rktd and .rktl.

In older versions, you can enable filetype detection of Racket files as Scheme with the following:

  if has("autocmd")

    autocmd filetypedetect BufReadPost *.rkt,*.rktl,*.rktd set filetype=scheme


If your Vim supports the ftdetect system, in which case it’s likely new enough to support Racket already, you can nevertheless put the following in "~/.vim/ftdetect/racket.vim" ("$HOME/vimfiles/ftdetect/racket.vim" on MS-Windows; see :help runtimepath).

  " :help ftdetect

  " If you want to change the filetype only if one has not been set

  autocmd BufRead,BufNewFile *.rkt,*.rktl,*.rktd setfiletype scheme

  " If you always want to set this filetype

  autocmd BufRead,BufNewFile *.rkt,*.rktl,*.rktd set filetype=scheme