Just another little note of "woah, vim already does that"

39 views
Skip to first unread message

Tim Chase

unread,
Feb 27, 2018, 1:34:42 PM2/27/18
to v...@vim.org
I've got a rather large source file for an ETL process containing
several functions (one for each of the files it processes). There's
enough similarity between the file processing that it's easy to do a
search and end up in the wrong function without noticing.

Knowing vim supported matching/colorizing based on line-numbers, I
started out with

:match Error /\%<50l\|\%>120l/

to match anything outside the function I was focused on. But as I'd
edit, those boundaries would change. So I start grumbling, wishing
that vim supported similar functionality for marks instead of
absolute line numbers. BUT HO! It DOES!

So I dropped mark "a" at the beginning of my function, dropped mark
"b" at the end of my function, issued

:match Error /\%<'a\|\%>'b/

and lo, it updates automatically, highlighting the regions outside
the current function. And when I move to the next function, I drop
the "this is the beginning" and "this is the end" marks, and it
updates.

It continues to delight me that vim still holds new/undiscovered
tricks, even after using vim for ~18yrs now.

Anyways, thought I'd share in case it was useful for anybody else.

-tim




Arun

unread,
Feb 27, 2018, 2:05:55 PM2/27/18
to vim...@googlegroups.com, v...@vim.org
Very true, vim always amazes me. The learning is always there which keeps
it ever interesting.

As for the above issue, "folds" are good too.

- goto just before start of function and: zfgg
- after end of function: zfG

To prevent search from opening folds:
  :set foldopen-=search

For running commands that skips closed folds
  :foldd {cmd}

Regards,
-Arun 
Reply all
Reply to author
Forward
0 new messages