[Claus Reinke] [Haskell Mode Screencasts] [Haskell Mode Trac] [Haskell Mode Blog Entries] [source repo rss feed]

Haskell mode for Vim

There is no such thing as a one-ring-to-rule-them-all Haskell mode for Vim, but syntax highlighting comes as standard, and most Vimmers have their own collection of Vim script plugins, to activate and enhance at least some of Vim's multitude of source code editing functionality. This page is about my own versions, you can find other efforts in haskell.org's Vim corner.

If you've not used these haskellmode plugins before, or haven't used Vim at all, you might find this short series of screencasts interesting. It offers a quick tour of the features available when editing Haskell code with Vim, haskellmode for Vim, not to mention other Vim plugins. Don't forget to visit vim.org for more scripts, tips, and full online version of Vim's built-in help.

Let me know if these plugins work for you, they keep evolving whenever I run into a persistent issue that I'd like them to help me with, and I sometimes introduce bugs!-) Things should work on all ghc/vim platforms; there are not always useful defaults for all platforms, and sometimes the Haddock docs are not installed by default, so you might have to do some configuring, but I have tried to fix bugs as they were reported (feature suggestions are also welcome, but may take longer). Please note that I have not been able to spend the necessary time on my Haskell interests recently, and that also implies occasional gaps in updates to these haskellmode plugins (please remain patient, and keep reporting issues, especially when newer versions GHC/Haddock/etc interfere with the way the plugins work).

current: vimfiles/haskellmode-20101118.vba

All in one, as a vimball archive. This is the recommended way of installing these plugins (if you just want to extract the sources or need to install in other than the default location, please check the vimball documentation). After installation, try :help haskellmode to find out more details about the features provided by these haskell mode plugins (or peek at the help file source here).

There is a log of open issues and recent changes and an issue tracker for your bug reports. You can also try to follow the haskellmode tag on my blog to keep up to date with plugin development and occasional update releases.

Source repo:
There is a darcs repo: http://code.haskell.org/haskellmode-vim/ with an rss feed for commit messages.

Not needed for general use (you can unpack the sources from the vimballs), but useful if you want to prepare patches, or if you want to keep local modifications, or if you just generally prefer source control repos over vimballs (see darcs home page).

  darcs get http://code.haskell.org/haskellmode-vim/
  darcs pull -a http://code.haskell.org/haskellmode-vim/


use the vimball archive (vimball is a standard plugin, and straightforward to use; mostly open the archive in Vim and source it, :so %; for details and alternatives, see :help vimball) - it will copy the individual scripts to your .vim/ or vimfiles/ directory and install the helpfile.

the haskell_*.vim files from the filetype-plugin directory will be loaded automatically when editing haskell files (NB: this assumes that you have set :filetype plugin on -- see :help filetype-plugin-on). to configure the web browser and to load the ghc compiler plugin for .hs file, add the following in your .vimrc:

  " use ghc functionality for haskell files
  au Bufenter *.hs compiler ghc

  " switch on syntax highlighting
  syntax on

  " enable filetype detection, plus loading of filetype plugins
  filetype plugin on

  " configure browser for haskell_doc.vim
  let g:haddock_browser = "insert path to your web browser"
    "let g:haddock_browser = "C:/Program Files/Opera/Opera.exe"
    "let g:haddock_browser = "C:/Program Files/Mozilla Firefox/firefox.exe"
    "let g:haddock_browser = "C:/Program Files/Internet Explorer/IEXPLORE.exe"
For Macs, Sean Leather recommends (would all other Mac users be happy with this as default?)
  " Configure browser for haskell_doc.vim
  let g:haddock_browser = "open"
  let g:haddock_browser_callformat = "%s %s"
next, edit some Haskell file, call ':DocSettings', and check whether you are happy with what the script has found: g:haddock_browser will be called to display HTML docs (if you need to send your browser into the background, you could set g:haddock_browser_callformat), s:libraries should point to your local copy of the haddock files (if it doesn't, you could set g:haddock_docdir), and s:haddock_indexfile should be a place where vim can cache the information it gathers from the HTML files, so that it only has to do that once per version of the libraries (you can specify another directory for this cache file by setting g:haddock_indexfiledir); if you're happy with the settings, :DocIndex will populate the index, and :ExportDocIndex will store it for future use

Btw, if your GHC installation came without documentation, you can find documentation tarballs at http://www.haskell.org/ghc/docs/.

Before version 20090430, haskellmode used to set completeopt=menu,menuone,longest. I still recommend having menu,menuone in there, but haskellmode no longer interferes with that setting, and in future, other haskellmode menus will take a lead from the presence or absence of menuone there (_? already does).

Thanks to all of you who have provided feedback and suggestions on earlier versions, especially on removing portability issues.