Vimclair BASIC

Description of the page content

A Sinclair BASIC preprocessor written in VimL


Brief description

Vimclair BASIC is two things:

  1. An improved version of Sinclair BASIC.
  2. A program, written in VimL, the programming language of Vim, that converts a Vimclair BASIC source file to a TAP file with its Sinclair BASIC equivalent.

Actually, Vimclair BASIC is just a Sinclair BASIC preprocessor — but it looks, feels and works like a different, say modern, language, to some extent.

Motivation and goal

In summer 2014 I had the idea to start a new project in Sinclair BASIC for the ZX Spectrum +3e, but I missed two things:

  1. The improvements of SAM Coupé's MasterBASIC (a descendant of ZX Spectrum's Beta BASIC): control structures, procs, labels, long variable names…
  2. The Vim editor. Vim has been my main work tool for many years. I can not imagine writing code, in any language, without the endless power of Vim.

I investigated and tried all the available tools that convert Sinclair BASIC from plain text files to actual emulator files, but no-one was exactly what I needed, so finally I decided to write my own tool, based on previous related works of mine (BBim, MBim and SBim).

I have been writting my project in Vimclair BASIC for the ZX Spectrum +3e along with Vimclair BASIC itself, so the preprocessor has been tested during the development.

Vimclair BASIC is not finished yet. There are some pending fixes and new features. But it works fine enough to be used for real projects.


Vimclair BASIC is a Sinclair BASIC preprocessor that makes development easier.


  • C-style block and line comments.

  • Bash-style line comments.

  • Labels instead of line numbers.

  • #vim directive to execute any Vim command in the source.

  • Long variable names for strings, arrays and FOR loops, using the #vim directive to make the substitutions.

  • Control structures (can be nested):

    • DO …​ LOOP

    • DO …​ LOOP UNTIL

    • DO …​ LOOP WHILE




    • DO WHILE …​ LOOP



    • EXIT DO

    • EXIT FOR

    • IF …​ THEN …​ ENDIF

    • IF …​ THEN …​ ELSE …​ ENDIF

    • IF …​ THEN …​ ELSE IF …​ ELSE …​ ENDIF (with any number of ELSE IF)

  • Procedures (without parameters):


  • Procedures with parameters can be simulated ad hoc with the #vim directive.

  • The CALL command can be changed with #procedureCall, e.g.: #procedureCall proc or even make it empty: #procedureCall.


  • README.adoc: This file.

  • LICENSE.txt: The license.

  • Command line wrapper for the Vimclair BASIC to TAP converter.

The vim/ directory contains Vim specific files:

  • vim/vbas2tap.vim : Vimclair BASIC to TAP converter.

  • vim/ftdetect/vimclairbasic.vim : filetype detect (how Vim knows, by the filename extension, that you are opening a Vimclair BASIC source file).

  • vim/ftplugin/vimclairbasic.vim : filetype plugin (configuration and editing preferences for Vimclair BASIC source files).

  • vim/syntax/vimclairbasic.vim : syntax highlighting file.


The preprocessing of the source is done by Vim, so it must be installed in the system, even if other editor is used to edit the sources.

In order to convert the sources to a TAP file, Vimclair BASIC needs either BAS2TAP (by Martijn van der Heide) or zmakebas (by Russel Marks). The #tapmaker directive is used to choose one of them; if the #tapmaker directive is empty or missing, no TAP will be created, but only the BAS file.


At the time of writing (2016-11), its latest version (v2.6, release 2013-01-20), can be obtained from the utilities section of World of Spectrum.

This is how I compiled and installed BAS2TAP on Raspbian and Debian:

   gcc -Wall -O2 bas2tap.c -o bas2tap -lm
   strip bas2tap
   sudo mv bas2tap /usr/local/bin/


At the time of writing (2015-03), its latest version (1.2, release 2004) is a package of Debian, Raspbian, Ubuntu and probably other distros. Also the sources are easy to find (example:

The original code had a bug: The tokenization of DEF FN doesn’t include the required 5 bytes for each parameter. This made FN fail. This bug was fixed by Antonio Villena in his own version:


Extract the contents of the tar file:

tar xvz vimclair_basic.tar.gz

Enter the new directory:

cd vimclair_basic

Copy the content of the vim/ directory into your ~/.vim/ directory:

cp -r vim/* ~/.vim

Create a link to , with your command name of choice (e.g. vbas2tap ), into a directory in your path (usually ~/bin/ or /usr/local/bin/ ):

ln -s ~/bin/vbas2tap

If you prefer the system-wide /usr/local/bin/ directory:

sudo ln -s /usr/local/bin/vbas2tap

In the examples above, symbolic links are used. You can create hard links instead, copy or even move the file.


Vimclair BASIC source files use the VBAS filename extension by default, but you can change it in ~/.vim/ftdetect/vimclairbasic.vim.

Whenever you open a Vimclair BASIC program with Vim, the proper syntax highlighting will be selected, and the normal-mode key map .tap (defined in vim/ftplugin/vimclairbasic.vim ) will convert your source to a TAP file.

You can use also the command line converter from your OS shell:

vbas2tap program.vbas


Vimclair BASIC in GitHub.

Related pages

A BASIC preprocessor written in Vim.
Cross-development toolkit for MasterBASIC and SimCoupe.
An S*BASIC preprocessor.
CE4 [para ZX Spectrum +3e]
[Proyecto:] Juego de aventuras de texto con gráficos, escrito en Vimclair BASIC para ZX Spectrum +3e.
Initial development history of Vimclair BASIC