5

Haskell has a literal syntax for anonymous functions of

\pattern0 pattern1 [...] patternN -> expression

which interacts oddly with vim's parenthesis text objects when pattern0 starts with a (.

For example in the line

foldr (\(a,b) c -> a + b * c) 0 [ (0,1), (2,3) ]
          ^

If my cursor is on the , in (a,b), I'd like the normal mode command di( to delete the a,b and leave the cursor on the ), like so:

foldr (\() c -> a + b * c) 0 [ (0,1), (2,3) ]
         ^

However, with cpoptions=aABceFs, the \ prevents the ( from matching the ) in \(a,b), so the entire start of the lambda expression is deleted:

foldr () c -> a + b * c) 0 [ (0,1), (2,3) ]
       ^

With cpoptions=aABceFsM, it's a little better as % works properly, but the entire lambda expression is deleted:

foldr () 0 [ (0,1), (2,3) ]
       ^

How can I get di( to just delete a,b?

  • 1
    That's really strange. It seems like a bug to me. This isn't the ideal solution, but you could do :nnoremap di( vT(Ot)d The only downside is that this doesn't work with ci(, yi(, vi(, da( and the endless variations. – DJMcMayhem May 20 '16 at 16:47
  • DJ McMayhem: I think you're right. I had this bug using an old version of 7.4 (2013 Aug 10, unpatched). di( works as desired in newer versions. – rampion May 20 '16 at 17:58
4

This is a bug in vim that was patched in version 7.4.662, update and di( will work as desired.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.