1

When running an Ex command in Vim on range of lines, the range is always extended to cover adjacent folds (which is documented in :help fold-behavior). For example, given the following file:

int foo() {
  foobar();
}

the :2s/o//n command (i.e. counting o's in second line), will print:

2 matches on 1 line

However, if I fold the whole file, I get:

4 matches on 2 lines

Is there any way to override / workaround this behavior? I want to run my command on precisely specified range of lines; I don't care about folds.

rburny
  • 1,559
  • 1
  • 9
  • 28
  • I've found out that I can check whether a specific line is folded using `foldclosed` and `foldclosedend` methods. This at least allows detecting the problematic situation. – rburny Oct 17 '15 at 20:24
  • 2
    If everything else fails: disable folds, do your thing, re-enable folds. – Sato Katsura Oct 17 '15 at 20:53
  • @SatoKatsura : thanks, I just tried it and it works remarkably well. I'm surprised that all folds survive such operation. Do you know if there's anything else to watch for (e.g. any side effect of this toggling)? – rburny Oct 17 '15 at 22:20
  • 2
    As far as I know there are no side effects. The problem with such toggle is that it involves screen refreshes, and that's insanely expensive for a simple regexp match. – Sato Katsura Oct 18 '15 at 06:12
  • I'm using your idea successfully. Please turn your comment into an answer so I can accept it. – rburny Oct 28 '15 at 17:26

0 Answers0