tags:

views:

191

answers:

2

Full source here: http://www.vim.org/scripts/download_script.php?src_id=10391

The line is:

    silent %s/[^λ←→≲≳≡≠⇒»∙∀\\\-!#$%&*+/<=>?@\^|~.]\@<=\\\([^λ←→≲≳≡≠⇒»∙∀\\\-!#$%&*+/<=>\?@\^|~.]\)/λ\1/eg

Someone please decipher this for me. The larger script is intended to unicode-ify some operators in Haskell into more familiar mathematical equivalents.

+3  A: 

Full explanation for the line here: http://www.reddit.com/r/haskell/comments/8b0tf/haskell_unicode_cuteness_for_vim/

me2
+5  A: 

As the author of that line, I can translate. Complicated regular expressions are often 'write-only' and this relies on a vim regex extension.

The purpose of this is to make sure that it doesn't do the replacement of \ with a pretty printed λ in the middle of an operator like \\.

It checks to make sure that the character that precedes us in the buffer is not a valid operator symbol (the meaning of everything everything up to the \@<=). The \@<= is a 'zero width match look behind', which only succeeds if the stuff to the left of it occurs, but doesn't include it in the resulting match.

And then the \([^...]\) part checks to make sure that the stuff that follows us is a non-symbol as well, in which case, we match it, and then include it in the output thanks to the \1 in the result.

Note, this isn't perfect. Unfortunately, It will still replace backslashes inside of strings, but it works rather well.

Edward Kmett