English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-11-03 (20:58)
From: Markus Mottl <mottl@m...>
Subject: VIM-hints

I guess that there are quite some people who use the editor VIM (Vi
Improved) out there (see: www.vim.org). I have just tried to find out some
more extras of VIM and found a very convenient way of building and
debugging OCaml programs so I thought that you might also want to learn
about it:

VIM allows you to specify patterns which scan output produced by the
compiler and/or during the make process. By teaching VIM the patterns that
normally appear when the OCaml-compilers find a bug, it is possible to have
the editor automatically load the corresponding file and place the cursor
at the exact line + column.

If you also bind, say, a function key to calling "make", you never have to
leave the editor anymore.

The following variable settings seem to be very useful for this purpose -
put them in your ".vimrc"-file:

map <F5> :make<RETURN>
au BufNewFile,BufRead *.ml,*.mli,*.mll,*.mly set expandtab hidden autowrite efm=%+AFile\ \"%f\"\\,\ line\ %l\\,\ characters\ %c-%*\\d:,%Z%m

The first line binds a function key to calling the appropriate "make" (the
latter can be configured with e.g. "set makeprg=gmake").

The second line (it's just one - this is important!) says what has to be
done when you create a new file or open an existing one with the
corresponding OCaml-suffixes. The options in this line have the following

  * "expandtab" - use spaces instead of tabs when the tabulator key is used
                  (I recommend this in general for sources).

  * "hidden"    - Very important! If you call "make" and there is an error,
                  VIM will open the file containing it, but forgets about
                  the one that you changed - no undo anymore! This option
                  orders VIM to not forget about old buffers...

  * "autowrite" - if you set this, then you do not have to save the files
                  before executing "make" anymore.

  * "efm"       - the patterns for which VIM scans the output of the
                  building process. See the help on "quickfix" in VIM for
                  more details.

I have found that (at least for me) these features give quite some boost in
development speed, especially if you want to rename things or if a small
change requires many further changes in different parts of the program:
then making use of the above features will (in most cases) help you track
down all code parts that require an update - just "make" and let VIM do the

Happy VIMing!

Markus Mottl

Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl