I accidentally stumbled on a solution for a problem I had: I wanted to get an overview over all occurrances of the word under the cursor, after I used #
to find them individually.
For some reason I guessed the command :g %
and it did what I wanted. But I could not find an explanation of this, neither by reading :help :g
nor :help g
nor :help %
nor :help pattern
nor :help cword
.
I experimented some more with this and I figured out
- that it had nothing to do with the cursor position and it would just repeat the last search,
- that I could replace the
%
with any single character (or at least, all that I tried worked), but there had to be one, and there had to be at least one space between:g
and that character.
For example, :g a
, :g x
, :g #
, :g c
all worked.
Typing one more character would use this as a start of a new search apparently.
Where can I find the documentation for this invocation? :help :g
shows :g/{pattern}/[cmd]
and does say that the /
can be replaced by a different character, so I figured it could be a space, but then the syntax should be
:g<space>{pattern}<space>[cmd]
and I understand that the default cmd
is :p
which prints the matching lines, but I still don't understand why the last search pattern is inserted automatically and what the relevance of that trailing other character (%
, a
, x
above) is.
I'm using Vim 8.2.2434.