Skip to content

Vim Soar Plug-In

This package allows you to edit your Soar files in vim more easily by providing the following capabilities:

  • Syntax highlighting
  • Auto-indenting
  • Moving around by productions
  • Toggling comment/uncomment productions
  • Code folding (You can fold a production into a single line)
  • Taglist support

Usage Instructions

Download the archive and expand it into $HOME/.vim (C:\Documents and Settings\user\vimfiles in Windows). You should have the following files:

File Description
ftplugin/soar.vim main configuration file
ftdetect/soar.vim makes vim recognize .soar files as filetype "soar"
indent/soar.vim auto-indentation configuration
syntax/soar.vim syntax highlighting configuration

Next, add the following lines to your .vimrc ( _vimrc on Windows):

1
2
3
4
 filetype on            " enable filetype detection
 filetype plugin on     " run ftplugin/soar.vim for .soar files
 filetype indent on     " enable custom indentation
 syntax on              " enable syntax highlighting

Note that if you're using terminal vim in *nix, you may also need to enable colors with

set t_Co=256

Now any file you open with the .soar extension should be highlighted and auto-indented. You should also be able to fold and unfold single productions using the standard zc and zo commands (see :help folding). Furthermore, there are some convenient keyboard shortcuts defined:

In normal mode:

Command Description
Alt-k Move to the previous production
Alt-j Move to the next production
Alt-c Toggle commenting out the production
Alt-a Create an application rule for the proposal rule the cursor is in

In insert mode, right after you finish typing a condition or action that ends with a variable, you can "chain" the variable into the next condition by pressing Alt-e. For example, if your cursor is at the location of the X here:

sp {test
    (state <s> ^superstate <ss>)X

and you press Alt-e while in insert mode, the text will become:

1
2
3
sp {test
    (state <s> ^superstate <ss>)
    (<ss> ^X

and your cursor will have moved to the location of the X, ready for typing the attribute test.

Tag Lists

The taglist plugin for vim allows you to open a window that lists all the tags generated by the ctags program for files you're editing. With very little work it can be made to list productions in agent files. You can then jump to any production, even across different files, by navigating this list. This is quite useful when your productions are distributed across many files, for example if you created them with Visual Soar.

  1. Install Exuberant ctags from http://ctags.sourceforge.net or your Linux package manager.
  2. Install the taglist plugin from here.
  3. To get ctags to recognize Soar source code, add these lines into your $HOME/.ctags file (or C:\Documents and Settings\user\ctags.cnf in Windows):
1
2
3
--langdef=soar
 --langmap=soar:.soar
 --regex-soar=/^[ \t]*[gs]p[ \t]*\{[ \t]*([-a-zA-Z0-9_\*\|]*)/\1/p,production/

Note: Depending on your version of ctags, you may have to replace the escaped brace \{ with a regular brace. ctags should complain loudly about an unmatched brace if the syntax is wrong.

Now when you're editing a .soar file, you should be able to run the command :TlistOpen and get a list of all the productions in the current file. You can also use :TlistAddFiles *.soar to add all files in the directory.

Developer

Joseph Xu