You are looking at historical revision 20123 of this page. It may differ significantly from its current revision.


Following are some settings used to edit Scheme file with VIM.


VIM's default syntax file for Scheme already has some Chicken-specific settings, we can enable those by adding the following line into ~/.vim/ftplugin/scheme.vim.

let g:is_chicken=1

But still some annoyances remain.

The following code is a patch to syntax/scheme.vim, you can patch the system-side file, or you can copy it to ~/.vim/syntax, and then patch it. This patch adds S-expression comment and Unix hash-bang support.

--- old-scheme.vim      2008-08-16 09:35:17.000000000 +0800
+++ scheme.vim  2008-08-16 09:34:38.000000000 +0800
@@ -29,6 +29,11 @@
 syn match      schemeError     oneline    ![^ \t()\[\]";]*!
 syn match      schemeError     oneline    ")"
+" Add TempStruc before Struc and Quoted.
+" although TempStruc will be overwritten by them when do hightlighting,
+" it still can be used to delimit a sexp.
+syn region schemeTempStruc start="(" end=")" contained transparent contains=schemeTempStruc
 " Quoted and backquoted stuff
 syn region schemeQuoted matchgroup=Delimiter start="['`]" end=![ \t()\[\]";]!me=e-1 contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
@@ -231,8 +236,13 @@
 if exists("b:is_chicken") || exists("is_chicken")
+    syn match schemeChar oneline "#\\return"
+    syn match schemeChar oneline "#!eof"
     " multiline comment
     syntax region schemeMultilineComment start=/#|/ end=/|#/ contains=schemeMultilineComment
+    syn region schemeSexpComment start="#;(" end=")" contains=schemeComment,schemeTempStruc
+    hi def link schemeSexpComment Comment
     syn match schemeOther oneline    "##[-a-z!$%&*/:<=>?^_~0-9+.@#%]\+"
     syn match schemeExtSyntax oneline    "#:[-a-z!$%&*/:<=>?^_~0-9+.@#%]\+"
@@ -268,6 +278,9 @@
     " suggested by Alex Queiroz
     syn match schemeExtSyntax oneline    "#![-a-z!$%&*/:<=>?^_~0-9+.@#%]\+"
     syn region schemeString start=+#<#\s*\z(.*\)+ end=+^\z1$+ 
+    syn match schemeShebang "^#!/.*csi.*$"
+    hi def link schemeShebang Comment
 " Synchronization and the wrapping up...



VIM's completion functionality can be configured by 'complete' option. There are several useful settings for Scheme editing.

First is the k flag, we can supply a dict file to it. The following code can be used to generate a Scheme dict file.

!/usr/local/bin/csi -script
;;; Create a dictionary file to be used by vim insert complete.

(use data-structures extras srfi-1 srfi-4 srfi-13)
(use srfi-14 srfi-69 apropos regex srfi-18 posix utils tcp lolevel)

(call-with-output-file "~/scheme-word-list"
   (lambda (port)
     (for-each (lambda (x) (display x port) (newline port))
               (sort (apropos-list (regexp ".*") #:macros? #t)
                     (lambda (a b)
                       (string<? (symbol->string a)
                                 (symbol->string b)))))))

Then add the following line to ~/.vim/ftplugin/scheme.vim, and we will be able to complete identifier names using CTRL-P and CTRL-N.

setl complete+=,k~/scheme-word-list

Also when we edit c files, VIM finds words in not only opened buffers, but also included files. These are controlled by the following options.

Likewise, VIM can be configured to find words in files which are mentioned in use or require-extension. In the example below, change the path to match your setup. The follwing lines go into ~/.vim/ftplugin/scheme.vim:

setl include=\^\(\\(use\\\|require-extension\\)\\s\\+
setl includeexpr=substitute(v:fname,'$','.scm','')
setl path+=/usr/local/lib/chicken/3
setl suffixesadd=.scm


VIM already indents Scheme file well, except it can't recognise some Chicken keywords. We just have to add them.

setl lispwords+=let-values,condition-case,with-input-from-string
setl lispwords+=with-output-to-string,handle-exceptions,call/cc,rec,receive
setl lispwords+=call-with-output-file

Also, put those lines in to scheme.vim.

nmap &lt;silent&gt; == :call Scheme_indent_top_sexp()&lt;cr&gt;

" Indent a toplevel sexp.
fun! Scheme_indent_top_sexp()
	let pos = getpos('.')
	silent! exec "normal! 99[(=%"
	call setpos('.', pos)

Then we can use == to indent a toplevel S-expression.


Following is a simple way to add interaction facility to VIM using screen.

It was stolen from this link. Thanks Jonathan Palardy.

Put following lines into ftplugin/scheme.vim

nmap <silent> <leader>es :call Scheme_eval_defun()<cr>
nmap <silent> <leader>ef  :call Scheme_send_sexp("(load \"" . expand("%:p") . "\")\n")<cr>

fun! Scheme_send_sexp(sexp)
    let ss = escape(a:sexp, '\"')
    call system("screen -p csi -X stuff \"" . ss . "\n\"")

fun! Scheme_eval_defun()
    let pos = getpos('.')
    silent! exec "normal! 99[(yab"
    call Scheme_send_sexp(@")
    call setpos('.', pos)

First we create a window in screen with the name of csi and start csi in it. Then open a scheme file, using <leader>es to evaluate a sexp and using <leader>ef to load a file.