Ⅰ. 插件描述
A vim mode for HaskellⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'travitch/hasksyn'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'travitch/hasksyn'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'travitch/hasksyn'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/travitch/hasksyn
Ⅳ. 文档说明
# Introduction
hasksyn is a vim plugin to highlight and indent Haskell source code. It is
written almost entirely from scratch and has slightly different goals than the
original Haskell syntax highlighting code. Most importantly, this version
explicitly does not handle Literate Haskell files at all. In exchange, it
provides more comprehensive syntax highlighting for normal Haskell code, along
with fairly reasonable indentation. It also includes improved highlighting
for cabal files.
Unlike haskellmode-vim and
vim2hs, this package does not support running
external tools over code in fancy ways or recognizing cabal files.
Screenshot
Here is a screenshot of the syntax highlighting (included in the demos
directory):

Stability
This mode seems to work reasonably well. That said, it hasn't been thoroughly
- Additionally, configuration options are still subject to change.
Performance
I've tested things out on files around 1000 lines and it seems to perform well.
I don't see a visible slowdown with this code, whereas vim2hs was pegging a CPU
while scrolling. The indent code can do a non-trivial amount of work, but it
does not really seem to be an issue.
TODO
- Highlighting for
mdo,proc, andrec - Nesting block comments inside of haddock block documentation comments
- Indentation for quasi-quotes (maybe)
- More clever indentation, where sensible
Requirements
The code has only been tested with vim 7.3, but it should work for almost any
reasonable version. Feel free to report bugs; I'll try to support all
reasonable versions. There is also no platform-specific code.
Indentation Policy
As far as I can tell, this package should provide better Haskell indentation
than other modes. Here is a brief overview of its features:
- Smart handling of comments and strings; it should be doing the right thing
almost all of the time. The expected exception is if you are inside of a
very long block comment where the comment beginning is farther back than
the search allowance.
- Indent after where/case .. of/operators at the end of lines
- Align | and ,
- Align bindings in let expressions, and snap
into its proper spot - De-indent after
returnat the end of adoblock. - De-indent after the catchall case of a case expression.
Installation
With pathogen
Just clone into the standard pathogen location:
cd ~/.vim/bundle
git clone git://github.com/travitch/hasksyn.gitIf you use git submodules:
cd ~/.vim
git submodule add git://github.com/travitch/hasksyn.git bundle/hasksynManually
git clone git://github.com/travitch/hasksyn.git
cd hasksyn
cp -R * ~/.vimConfiguration
Below are the configuration options available, along with their default values.
If you want to change them, just copy the relevant line into your ~/.vimrc.
Indentation
" How many lines should be searched for context
let g:hasksyn_indent_search_backward = 100
" Should we try to de-indent after a return
let g:hasksyn_dedent_after_return = 1
" Should we try to de-indent after a catchall case in a case .. of
let g:hasksyn_dedent_after_catchall_case = 1Notes
If you use rainbow_parentheses,
do not enable RainbowParenthesesLoadBraces for Haskell files. It seems to
interfere with highlighting block comments.
I have also disabled so-called three part comments for Haskell. These
look like:
{-
-
-
-}These are three-part comments because of the start token {-, the middle token-, and the end token -}. Whatever vim does to make this magic happen was
interfering with the indentation script, so I disabled it. I also find it kind
of obnoxious. If you really want it back, I could make that configurable or
you can just use ~/.vim/after/ftplugin/haskell.vim.