Using VIM syntax file

For the impatient use:

  • Add the following to your .vimrc file:
    " Enable syntax
    :syntax on
    " This allows including the proper PLUMED syntax file:
    :let &runtimepath.=','.$PLUMED_VIMPATH
    " The former command requires PLUMED_VIMPATH to be set. Alternatively, use this:
    " let &runtimepath.=',/usr/local/lib/plumed/vim'
    " properly adjusted to the path where PLUMED is installed.
    " This makes autocompletion work in the expected way:
    :set completeopt=longest,menuone
    " This enables bindings of F2/F3/F4 to plumed specific commands:
    :let plumed_shortcuts=1
    
  • When you open a PLUMED input file, you can enable syntax highlighting with:
    :set ft=plumed
    
    This will also enable autocompletion. Use <CTRL-X><CTRL-O> to autocomplete a word.
  • If you want to fold multi-line statements, type
    :setlocal foldmethod=syntax
    
  • While editing a plumed input file, you can use command :PHelp (or shortcut <F2>) to show in a split window a short help about the action defined in the line where the cursor is. Typing :PHelp again (or pushing <F2>) you will close that window. With <CTRL-W><CTRL-W> you go back and forth between the two windows.
  • When you open a file starting with #! FIELDS, VIM will automatically understand it is a PLUMED output file (VIM filetype = plumedf) and will color fields and data columns with alternating colors. Typing :PPlus and :PMinus (or pushing <F3> and <F4>) you can move a highlighted column.

See below for more detailed instructions.

Configuration

When PLUMED is compiled, directories help and syntax will appear in builddir/vim. They contain a VIM plugin that can be used to highlight proper PLUMED instructions in a PLUMED input file and to quickly retrieve help. There is also a file builddir/vim/scripts.vim that helps VIM in recognizing PLUMED output files.

Warning
Notice that these file do not appear if you are cross compiling. In this case, you must copy the plugin files from another machine.

To make VIM aware of these files, you should copy them to your $HOME/.vim directory. Later you can enable plumed syntax with the command

:set ft=plumed

If you work in an environment where several PLUMED versions are installed (e.g. using env modules), we recommend the following procedure:

  • Install PLUMED
  • Add to your .vimrc file the following line:
    :let &runtimepath.=','.$PLUMED_VIMPATH
    

The modulefile provided with PLUMED should set the PLUMED_VIMPATH environment variable to the proper path. Thus, when working with a given PLUMED module loaded, you should be able to enable to proper syntax by just typing

:set ft=plumed

in VIM. Notice that the variable PLUMED_VIMPATH is also set in the sourceme.sh script in the build directory. Thus, if you modify your .vimrc file as suggested, you will be able to use the correct syntax both when using an installed PLUMED and when running from a just compiled copy. Finally, in case you have both a pre-installed PLUMED and you have your development version the following command would give you the optimal flexibility:

:let &runtimepath.=','.$PLUMED_VIMPATH.',/opt/local/lib/plumed/vim/'

The environment variable PLUMED_VIMPATH, if set, will take the precedence. Otherwise, vim will resort to the hard coded path. In this case we assumed that there is a PLUMED installed in /opt/local/ (e.g. using MacPorts), but you can override it sourcing a sourceme.sh file in the compilation directory or loading a PLUMED module with module load plumed.

If you are tired of typing :set ft=plumed, you can use a modeline. Add to your .vimrc file the following commands

:set modeline
:set modelines=5

Then, at the beginning of your PLUMED input file, put the following comment:

Click on the labels of the actions for more information on what each action computes
tested on master