Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

% doesn't work when editing Haskell code in vim?

Tags:

vim

haskell

When I put the cursor on a parenthesis in vim:

f = (\x y -> x+y)
    ^

typing % will move the cursor to the matching parenthesis:

f = (\x y -> x+y)
                ^

typing %d will delete the parentheses and everything in them

f = 
   ^

but when I have nested parentheses:

g = (\(x,y) -> x+y)
    ^

typing % makes it jump to the closing inner parenthesis instead of the matching one:

g = (\(x,y) -> x+y)
          ^

and %d has the same mismatching behavior:

g = (\(x,y) -> x+y)
    ^

becomes

g =  -> x+y) 
    ^

Why? How can I make it match properly?


Oddly, the visual highlighting of matching parentheses does work:

abcdef

How does this work but then the matching by % doesn't? Are there two brains?

like image 534
Dog Avatar asked Oct 05 '13 19:10

Dog


1 Answers

Short answer, from :help %:

:set cpoptions+=M

This prevents vim from ignoring the \( combination and treat it as (.

(The long answer might involve using a similar plugin to matchit, of which I am unaware, that explains to vim that \ means lambda, not backslash.)

like image 107
Josh Lee Avatar answered Oct 18 '22 12:10

Josh Lee