1

Is there a way to automatically highlight the region enclosed by parentheses when the cursor goes over that region?

Take the following text as an example:

(define (example x)
  (cond ((string? x) (display x))
             (else (error "Bad" x))))

when the cursor goes above the cond, this particular region should be immediately highlighted (i.e. there should be no need to press any keys to achieve highlighting):

(cond ((string? x) (display x))
           (else (error "Bad" x))))

Useful screenshot from something similar in emacs: https://www.emacswiki.org/emacs/HighlightSexps

Emacs Highlight Sexps screenshot

I believe this highlighting feature will make reading s-expressions (basically Racket, Scheme, Clojure, Common Lisp code) a lot easier.

How can this highlighting be achieved in vim?

Flux
  • 9,805
  • 5
  • 46
  • 92

1 Answers1

0

You can use va( (start visual mode, select from the previous opening ( to the corresponding closing ), including (with i(: excluding) the parentheses themselves). To remove the highlighting and go back to where you were, use <Esc>``.

I know that this is only a partial solution, but this is what you can get with built-in functions. More than that would require a plugin, but I don't know whether such exists.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • I was looking for automatic region highlighting (instead of manual), and was surprised that this need has not been fulfilled by any plugins. Maybe this need is uncommon... Thank you for the information. – Flux Nov 16 '17 at 18:47
  • Well, keep searching... I just mentioned that _I_ don't know any such plugin. But there are related ones, like [MatchTag](https://github.com/gregsexton/MatchTag) for HTML tag highlighting. – Ingo Karkat Nov 17 '17 at 11:45