22.3 Vim

Many distributions of Vim ship with support for Scheme, which will mostly work for Racket. You can enable filetype detection of Racket files as Scheme with the following:

  if has("autocmd")

    au BufReadPost *.rkt,*.rktl set filetype=scheme

  endif

Alternatively, you can use the vim-racket plugin to enable auto-detection, indentation, and syntax highlighting specifically for Racket files. Using the plugin is the easiest method, but if you would like to roll your own settings or override settings from the plugin, add something like the following to your ".vimrc" file:

  if has("autocmd")

    au BufReadPost *.rkt,*.rktl set filetype=racket

    au filetype racket set lisp

    au filetype racket set autoindent

  endif

However, if you take this path you may need to do more work when installing plugins because many Lisp-related plugins and scripts for vim are not aware of Racket. You can also set these conditional commands in a "scheme.vim" or "racket.vim" file in the "ftplugin" subdirectory of your vim folder.

Most installations of vim will automatically have useful defaults enabled, but if your installation does not, you will want to set at least the following in your ".vimrc" file:

  " Syntax highlighting

  syntax on

  

  " These lines make vim load various plugins

  filetype on

  filetype indent on

  filetype plugin on

  

  " No tabs!

  set expandtab

Indentation

You can enable indentation for Racket by setting both the lisp and autoindent options in Vim. However, the indentation is limited and not 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.

If you use the built-in indenter, you can customize it by setting how to indent certain keywords. The vim-racket plugin mentioned above sets some default keywords for you. You can add keywords yourself in your ".vimrc" file like this:

  " By default vim will indent arguments after the function name

  " but sometimes you want to only indent by 2 spaces similar to

  " how DrRacket indents define. Set the `lispwords' variable to

  " add function names that should have this type of indenting.

  

  set lispwords+=public-method,override-method,private-method,syntax-case,syntax-rules

  set lispwords+=..more..

Highlighting

The Rainbow Parenthesis script for vim can be useful for more visible parenthesis matching. Syntax highlighting for Scheme is shipped with vim on many platforms, which will work for the most part with Racket. The vim-racket script provides good default highlighting settings for you.

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.

Scribble

Vim support for writing scribble documents is provided by the scribble.vim plugin.

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. 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 Vim installation.