Introduction

Coloring

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.

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:

Interaction

Vim lacks a cross-platform facility to spawn shells and other commandline programs and interact with them, therefore various methods—or workarounds—have been invented and re-invented over time to address the issue. Each has its own advantages and drawbacks.

Using VimSh

This is a Vim extension written in Python that approximates what most users would consider the "ideal" shell interaction from within a text editor. It can spawn any interactive program from inside Vim, display their output in a new buffer (a Vim window) and receive input on the bottom line of the same buffer. Since it's a Vim buffer you can go into normal mode and move around the buffer, yank, paste, use word completion, etc. (Do understand that changing text and typing newlines in places other than the bottom line will give weird results.)

You will need a Vim built with Python support (:version must contain +python) and an OS with pty support (Windows users are SOL.)

The code above includes work from various sources and contains a few weird tricks (in other words: here be dragons) It provides several features under the S leading character. Redefining S as Shell (or Send) shouldn't cause problems for most users, as the default Substitute function is just a synonym for Change, but you can alter the mappings if you don't like it.

Sn

open a new shell

SS or countSS

send the current line (or count lines) to the shell

Smotion

send the text over motion to the shell (eg. S3w sends 3 words to the shell)

visual mode S

send the selected text (either char-, line-, or block-wise selection)

Sf

send the entire file to the shell

St

send the current top-level form to the shell

A newline is always added at the end of the text being sent, so as to make the shell execute it. If for some reason you don't want to send a complete command, you will have to use Vim's standard yank & pull (copy & paste) from your editing buffer to the shell buffer.

Care is taken to make the shell react to each individual line as if it was typed interactively. As a result, pasting huge chunks will be a slow operation. You are advised to use a source command in this case: source (or dot) for bash, include for Chicken.

Important notice: because of a limitation in Vim, when a line takes more than a given timeout (1/10 of a second) to execute, VimSh returns the command to the editor without waiting for the shell to complete the operation. You will have to manually go to the VimSh buffer every once in a while and hit F5 to refresh the view. This is probably the most annoying drawback of this whole method, but it's not that bad in actuality.

The config block above spawns bash, instead of csi, for several reasons:

to have bash initialize the environment properly

to be able to read any csi fatal errors

to use this framework for other languages / interpreters.

One last thing, you might like this if you're not using it already:

set mousefocus

Using GNU Screen

Another way to add interaction facility to Vim is to use GNU Screen.

With this method the csi process is completely independent (detached) from Vim. It must be started manually, in a Screen session with a specific window title, and remains running after quitting the editor. This can be either an advantage or a disadvantage, depending on your requirements.