I'm trying to utilize section
movement via [[
, ]]
and friends, but I'm not seeing the behavior I'm expecting given my understanding of the documentation.
A section begins after a form-feed () in the first column and at each of a set of section macros, specified by the pairs of characters in the a set of section macros, specified by the pairs of characters in the 'sections' option. The default is "SHNHH HUnhsh", which defines a section to start at the nroff macros ".SH", ".NH", ".H", ".HU", ".nh" and ".sh".
The "]" and "[" commands stop at the '{' or '}' in the first column. This is useful to find the start or end of a function in a C program. Note that the first character of the command determines the search direction and the second character the type of brace found.
Granted, I don't understand nroff macros, so maybe that's the gap, but the second paragraph mentions moving to the next '{' or '}' character in the first column. However, when I type ]]
or [[
, I move to the bottom or top of the file, instead.
I tested in JS, CSS, HTML, and PHP files, and since vim's defaults are mostly for C, I tried again in a C file, but all with the same result.
Is there something I'm missing about this?
Tested in vim and nvim with -u NONE
.
Thanks in advance!
EDIT:
Here's the C file (which I expect to work the best) that I'm testing against.
#include <stdio.h>
// My comment
void main() {
void a, b;
a = 11;
b = 99;
printf("Values before swapping - \n a = %d, b = %d \n\n", a, b);
a = a + b; // ( 11 + 99 = 110)
b = a - b; // ( 110 - 99 = 11)
a = a - b; // ( 110 - 11 = 99)
// another comment
printf("Values after swapping - \n a = %d, b = %d \n", a, b);
}
int yo() {
printf("hi there");
}
nroff
macros thing is a red herring: that bit of the documentation just means that if you have e.g. a line that begins.SH
in it, the section motions will move to it. If you're not editing an nroff file, then it's irrelevant to your problem.vim --clean
? It's juuust about possible that your problem is caused by a rogue mapping, even if you tested withvim -u NONE
.nroff
explanation! That makes sense; it only applies in an nroff file, although I'm sad I can't change those options to make the sections work differently. I tried withvim --clean
with the same result :(