A week ago, I mentioned Iedit mode. This is a real gem. It’s not part of Emacs, but you can install it from Elpa, and you won’t regret it.
It’s entry point is
iedit-mode, which highlights the current symbol (or region), and all its other occurrences in the buffer. (The exact rules of what is selected for iedit and how the selected text is searched for are a bit complicated. For instance, you can set
iedit-only-at-symbol-boundaries to nil, and then still a symbol is selected, but any its occurrence – also being e.g. part of another symbol – is highlighted. There are more variables which influence Iedit’s behavior, of course, like
iedit-case-sensitive. For some strange reason, it is not an option, so you can’t use
set-variable to change it, only e.g.
setq. Also, you can call
iedit-mode with a region active, and then the region is selected for Iedit.)
All this looks similar to Hi Lock mode, but there is a twist: if you actually edit the highlighted symbol, all its occurrences are changed accordingly! This is really great when you want to change the name of some function, variable etc. (OTOH, you have to be careful: iedit does not do any code analysis, and works also inside strings etc. Usually, this is what you want, because docstrings, but you might break something!)
As if that were not cool enough, there are more goodies here. If you actually
(require 'iedit) (as opposed to autoloading it, which is the case when you only install it from Elpa), the
iedit-mode is conveniently bound to
C-;. While in Iedit mode, you can press
C-' to turn yet another occur-like thingy: with it, only the lines containing the searched-for term (plus one line above and below for context – with prefix argument, you can change the number of these context lines) are actually displayed.
Another nice feature is a prefix argument of 0 for
iedit-mode. It restricts the search to the current defun. And did I mention that if you call
iedit-mode from isearch, it uses the current search string?
OK, enough fanboyism. Just install Iedit from Elpa and look up the docstring of
iedit-mode. You won’t be disappointed.