This page covers:
C-s
is a forward incremental search. M-%
to replace found occurrence.C-r
is a backward incremental searchM-x list-matching-lines
: list lines matching a regexp in the
current buffer.In search mode, the following bindings are available:
M-e
: Edit search stringM-s c
: Toggle case-sensitive searchM-s o
: List occurrences of search stringM-x multi-occur-in-matching-buffers RET .* RET <text> RET
: Search
in all open buffers.In Ibuffer, you can select buffers to do an incremental search on them. To mark buffers in the list, press m
.
Then:
M-s a C-s
: Incremental search on marked buffers. When the end of
a buffer is reached (with C-s
, it goes to the next marked one.
Once all the buffers have been searched, it rotates back to the
first buffer.M-s a C-M-s
: Isearch for regexp in the marked buffers.M-%
: query-replace
C-M-%
: query-replace-regexp
M-x find-name-dired t Q
: Prompts for interactive query-replace in files
selected in dired. Use y
to accept replace. C-x s !
to save
all.Newlines must be entered using C-q C-j
. For example, to remove
trailing commas in a JSON file, the regexp should be:
,\([
]+},\)
the newline being inserted with C-q C-j
.
^M
characters:M-% C-q C-M RET RET
M-x replace-regexp <RET> ^.\{0,72\}$ <RET>
\,(format "%-72sABC%05d" \& \#) <RET>
\&
: Represents the whole match being replaced\#
: Count of replacement so far, starting with 0\1
, \2
, …: Grouped match.\#1
, \#2
, …: Grouped match as a number.C-M-f
: forward-sexp
, Search matching parenthesis forwardC-M-b
: backward-sexp
, Search match parenthesis backward.M-x rgrep
: Does a recursive grep.grep-mode
:}
, TAB
: Next match<
: Beginning of buffer>
: End of the buffer.A tag file must be created with exuberant ctags, for example:
/usr/local/bin/ctags -e -R -f TAGS --tag-relative
This creates a tag file that will to need to be visited when first searching for a tag.
M-.
: search for a tagC-u M-.
: Find next matchM-*
: pop-tag-mark
, Go back to previous locationC-x w h <regexp> RET <face> RET
: Highlight regexp. To then deactivate highlighting, C-x
w r
.C-x w l <regexp> RET <face> RET
: Highlight lines containing regexp.M-x cd
: Change default directory. Often needed when using search
commands that operate from current directory.find-name-dired
: Searches file pattern in a given base directorylocate
: Searches file using a search string.Next: Select