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

    ==Introduction Following is some configures I use to edit scheme file with VIM. And My English is rather poor, so feel free to edit this page if you like.

    ==Coloring VIM's default syntax file for Scheme already have some stuff for Chicken Scheme, we can enable those by add following line into ~/.vim/ftplugin/scheme.vim.

    let g:is_chicken=1

    But It still remain some annoying stuffs. Following code is a patch to syntax/scheme.vim, you can patch the system file directly, or you can copy system file to ~/.vim/syntax, and then patch to it. This patch add S-exp comment and Shebang support.

    --- /usr/share/vim/vim71/syntax/scheme.vim	2008-08-02 09:45:48.000000000 +0800
    +++ scheme.vim	2008-08-02 14:52:12.000000000 +0800
    @@ -135,6 +135,9 @@
     syn match	schemeError	oneline    ,<[-a-z!$%&*/:<=>?^_~0-9+.@]*>[^-a-z!$%&*/:<=>?^_~0-9+.@ \t\[\]()";]\+[^ \t\[\]()";]*,
     " Non-quoted lists, and strings:
    +" Add TempStruc before Struc so that when do highlight, TempStruc will be
    +" overrighted. But TempStruc still can be used to delimit a sexp.
    +syn region schemeTempStruc start="(" end=")" contained transparent contains=schemeTempStruc
     syn region schemeStruc matchgroup=Delimiter start="(" matchgroup=Delimiter end=")" contains=ALL
     syn region schemeStruc matchgroup=Delimiter start="#(" matchgroup=Delimiter end=")" contains=ALL
    @@ -231,8 +234,16 @@
     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 schemeShebang "^#!/.*csi.*$"
    +    hi def link schemeShebang Comment
         syn match schemeOther oneline    "##[-a-z!$%&*/:<=>?^_~0-9+.@#%]\+"
         syn match schemeExtSyntax oneline    "#:[-a-z!$%&*/:<=>?^_~0-9+.@#%]\+"


    ===Completion VIM's completion manner can be configured by 'complete' option. Look through it's document and we can find something useful for our Scheme editing.

    First is the k flag, we can supply a dict file to it. So now using following code to generate a dict file. (I am a Scheme newbie, so feel free to enhance the code. :))

    !/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 match 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 following line to ~/.vim/ftplugin/scheme.vim, and we will be able to complete some stuff using CTRL-P and CTRL-N.

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

    Also when we edit c files, VIM find words in not only opened buffers, but also included files. Those were controlled by following options.

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

    With above lines inserted into ~/.vim/ftplugin/scheme.vim, VIM will also try to find words in files which we used for use or require-extension. You my have to change the path to satisfy you situation.

    ===Indention VIM already indent 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 <silent> == :call Scheme_indent_top_sexp()<cr>
    " 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.

    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.