• Stars
    star
    340
  • Rank 124,317 (Top 3 %)
  • Language
    Vim Script
  • Created over 12 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

vim2hs :: Vim -> Haskell

vim2hs ⦂ Vim β†’ Haskell

"Vim to Haskell": A collection of vimscripts for Haskell development.

Features

  • Written from scratch for clean and organized code, though some parts are borrowed from existing vimscripts.
  • Highlights Haskell code in GitHub Flavored Markdown, and Literate Haskell documents as Markdown.
  • Improved syntax highlighting including Haddock markup in comments, support for HSP and many quasi-quotes such as jmacro, shqq, regex, sql, string interpolation...
  • Liberal syntax highlighting for Cabal package descriptions, yielding less false-positives for mistakes than other syntax files for Cabal.
  • Makes Vim aware of Haskell modules and imports allowing you to gf with the cursor on a module to "go" to its source "file", etc.
  • Support for using HLint both as a compiler and a command, integrated into the quickfix system in Vim.
  • Unicode conceals for various operators and syntax, such as lambda and function composition.
  • Integrates with third-party plugins, but doesn't require them: snippets for UltiSnips and patterns for Tabular.
  • Posts buffers and line-ranges to hpaste.org.
  • Highly configurable, most of the above can be disabled if it gets in the way.

Installation

You need at least Vim 7.3, and for the HPaste command Python 2, not too ancient. Beyond that, just clone this repo and add it to your 'runtimepath'. Vundle is great for automating that, Pathogen is also popular.

See Also

Here are some other Vimscripts that complement vim2hs nicely:

  • Omni completion: neco-ghc
  • Syntax checking and linting: syntastic
  • Type inspection: haskellmode or (better) ghcmod
  • Shakespeare templates highlighting: html-template-syntax
  • Layout as text objects: textobj-indent (vim2hs includes a less powerful version of this that I wrote before I discovered this Vimscript; it might be removed in favor of this one in the future)

Overview

Top-level Definitions

The syntax highlighting of top-level definitions are improved in vim2hs:

Bindings screenshot

This screenshot showcases a number of nice features:

  • Type signatures are highlighted as a whole, even if spanning multiple lines.
  • In function definitions, the name of the function is highlighted differently from its arguments, even if the equal sign is on another line (most or all other syntax highlighters get this wrong).
  • Top-level definitions such as functions, classes and instances and data declarations form folds, as you can see in the foldcolumn to the left of the line numbers. Closed folds are given a consistent foldtext producing a nice overview of the code. Type signatures are intentionally not included in the folds, so as to allow you to read the type of folded definitions.

In this screenshot, "wide conceals" are enabled, which is what makes the type colons and function arrows display as unicode. This option is disabled by default, since it can mess up the visual alignment between lines. To enable it like I have done here, try this:

let g:haskell_conceal_wide = 1

Other options like this that are safer are enabled by default, and can be disabled should you so desire:

" disable all conceals, including the simple ones like
" lambda and composition
let g:haskell_conceal              = 0

" disable concealing of "enumerations": commatized lists like
" deriving clauses and LANGUAGE pragmas,
" otherwise collapsed into a single ellipsis
let g:haskell_conceal_enumerations = 0

Quasi Quoting

Haskell supports embedding arbitrary syntax that is processed at compile-time. Vim supports embedding external syntax highlighting.

Quasi Quotes screenshot

These are all enabled by default but you can selectively opt out by adding the relevant configuration overrides to your ~/.vimrc:

let g:haskell_quasi         = 0
let g:haskell_interpolation = 0
let g:haskell_regex         = 0
let g:haskell_jmacro        = 0
let g:haskell_shqq          = 0
let g:haskell_sql           = 0
let g:haskell_json          = 0
let g:haskell_xml           = 0

HSP & Heist

Haskell Server Pages and Haskell Source with XML pre-processes literal XML in Haskell source code into function application and vim2hs provides limited support for this syntax - I have yet to figure out how to highlight the body of XML elements differently while still highlighting the attributes as Haskell.

HSP screenshot

This is enabled by default and can be disabled thusly:

let g:haskell_hsp = 0

Heist is a simple XML/HTML templating system; simple enough that you could simply use the xml or html filetype in Vim for these templates. However, it includes a number of pre-defined "splices" and a special syntax for "splice interpolation" in attributes. Included with vim2hs is a syntax file for Heist HTML templates and automatic filetype detection for *.tpl files.

Heist screenshot

Strings

Haskell actually supports multi-line strings by escaping the newline, but I don't think it's a widely used feature and I think quasi quoting is better for such purposes. Thus, by default, I have opted to keep string literals from crossing lines so half your source file doesn't highlight as a string while you're entering one. Instead, string literals without a matching end quote highlight as errors.

Strings screenshot

There is a configuration option for this. To enable multi-line strings, use this:

:let g:haskell_multiline_strings = 1

HLint

HLint is provided as a compiler for Vim.

:compiler hlint
:make

As a convenience there's also a command that does the above and then resets the compiler to its previous value.

:HLint

Either way any HLint suggestions and warnings will be put in Vim's quickfix list and you can jump between them with :cn and :cp, although I recommend setting up FuzzyFinder and using its :FufQuickfix command instead.

HPaste

To pastebin the contents of the current buffer do this:

:HPaste

The newly created paste URL will be put in the + register, meaning your normal desktop clipboard.

Alternatively, you can select a range of lines with Vim's VISUAL modes and type the same as above, which should result in this:

:'<,'>HPaste

Which of course will paste the selected lines only.

If you get tired of entering your author name every time you can configure it globally like so:

let g:hpaste_author = 'donri'

UltiSnips

If you're using the excellent UltiSnips Vimscript, vim2hs provides some useful snippets for Haskell programming. You can list all active snippets by hitting Ctrl+Tab in INPUT mode.

Tabular

Another useful Vimscript is Tabular. If it's installed, vim2hs adds some named patterns useful for maintaining layout in Haskell code. You can list all named patterns by tab-completing after entering the :Tabularize command. You probably want to configure some mappings or commands for the ones you find useful.

To disable them, use this configuration:

let g:haskell_tabular = 0

More Repositories

1

vim-fish

Vim support for editing fish scripts
Vim Script
431
star
2

attest

Modern, Pythonic test automation
Python
100
star
3

all-about-monads

Attempt to port All About Monads to HaskellWiki
Haskell
54
star
4

flask-zodb

Use the ZODB with Flask
Python
41
star
5

amazing

an amazing widget manager for an awesome window manager
Ruby
25
star
6

flask-genshi

Genshi templating for Flask
Python
20
star
7

ruby-statgrab

Ruby bindings to the libstatgrab portable system statistics library
C
12
star
8

jbo

Use jbovlaste on the command line, offline.
Python
9
star
9

makfa-cli

Dependency-light (Python with batteries) single-file command-line makfa Lojban dictionary.
8
star
10

vlasisku

CSS
6
star
11

kibr

JVS2 Forever
Haskell
5
star
12

dotfiles

Vim Script
5
star
13

visual-camxes

JavaScript
5
star
14

path

Haskell
5
star
15

warp

DRY up your static hypertext
4
star
16

HUnit-Diff

Haskell
4
star
17

makfa

Supybot configs and plugins for the makfa lojban bot
Python
3
star
18

happstack-session

Haskell
3
star
19

flask-attest

Test Flask applications with Attest
Python
3
star
20

happaste

Haskell
2
star
21

bob

Bob is a generic source-and-binary-based package manager and builder
Ruby
2
star
22

wokkel4r

Abstractions on top of XMPP4R for a Wokkel (Twisted) like API
Ruby
2
star
23

happstack-yui

Moved to darcs
Haskell
2
star
24

data-lens-ixset

Haskell
2
star
25

cilre

Learn Lojban, already.
JavaScript
2
star
26

irc4r

IRC for Ruby
Ruby
2
star
27

kib

Ruby
2
star
28

heist-highlighter

Haskell
2
star
29

jbojme

Ruby
2
star
30

relvlast

Python
2
star
31

genshi

Python
2
star
32

detest

Python
2
star
33

cleaning-lady

Ruby
2
star
34

flatland

Python
1
star
35

perjury

1
star
36

rpmbuild

1
star
37

flask-sassy

Sassy CSS for Flask with pyScss
Python
1
star
38

braindump

Ideas and Experiments
Python
1
star
39

vim-hare

DANGER don't use this yet
Vim Script
1
star
40

vim-haskell

Vim Script
1
star
41

euler

Learning math and new programming languages by solving the Euler problems
Perl
1
star
42

rag

Python
1
star
43

stutuz

Prototypical foundation for a Lojban web infrastructure with a focus on Jbovlaste 2.
Python
1
star
44

dag.github.com

JavaScript
1
star
45

nox

Python
1
star
46

lojban-irc-stats

IRC statistics for #lojban on FreeNode
Perl
1
star