I often wish to search for variables that are simply called 'c' or 'count'.
For example
int c, count;
Unfortunately when I use an incremental search for 'c' or 'count' I get a lot of unnecessary hits like the 'c' in 'choice', or the 'count' in 'wordcount' which do not interest me. I know Emacs can do i-searches with regular expressions but I don't know the correct regular expression needed to match just 'c' and 'count'. These words are often surrounded by any number of white spaces. Anyone know the regex I can use to narrow my search?
Use isearch-forward-regexp
, usually bound to C-M-s, and search for \bc\b
or \bcount\b
In Emacs23, there's M-x isearch-forward-word (bound to M-s w) which does takes care of the word boundary (at the front) for you.
M-s w count
And, another keyboard shortcut for Andrew Stein's answer of using isearch-forward-regexp
is C-u C-s.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With