Finding regular expressions (such as variable names) in Vim

I often find I need to scan through my code to remember all the places an identifier such as a C variable or structure is used. One way to do this in Vim is to use the :grep command. In this demo, I'm looking for all the occurrances of the global variable M_is_pfunction_fitting.

The basic sequence in the demo is:

  1. I yank the variable into the buffer with 'yW'
  2. I grep for the variable I just yanked with ':grep ^R0'
  3. Once the grep has processed, I jump to the next instance several times using 'gn' (this is a custom mapping on my system)
  4. I look in the results list to see a list of all the grep results using ':cw'