My vimgrep search is not behaving as I would expect
I am performing the following vimgrep search (in vim(!))....
:vimgrep /^\s*bool\s\+\i\+\s*=\s*\(false\)\|\(true\);\s*$/ *[files....]*
in order to find bool variable initialisations in my code. It successfully returns all of the bool initialisations, e.g.
bool result1 = false;
bool result2=true;
but it also returns other lines where bool are assigned (not initialised), e.g.
开发者_高级运维result = true;
(i.e. it returns lines even when bool is not found at the start of the line).
I'd be grateful if anybody could tell me why it matches code where there is no "bool" type specifier at the start of the line.
Many thanks,
Steve.
:vimgrep /^\s*bool\s+\i+\s*=\s*(false)\|(true);\s*$/ [files....]
^ ^^^^ ^
You have some problems, both are marked:
Vim usesLooks like that was the SO parser problem (\(...\)
to group atoms, not(...)
.\(
not enclosed with backtics produces(
).- You should have
\|
inside parenthesis:\(false\|true\)
, or it will take it as «find either a lines where boolean variable is initialized as false (^\s*bool\s+\i+\s*=\s*\(false\)
part) or a line which containstrue
followed by a semicolon at the end of line (\(true\);\s*$
part)».
精彩评论