emacs

emacs Regular Expressions (regexp) Examples

||Symbols  Text a^2|| -> \norm{Symbols  Text a^2}

in Latex change I defined my own norm environment, using the \usepackage{amsmath} environment, by

\newcommand{\norm}[1]{\left\Vert#1\right\Vert}

Now I wanted to replace every pair || . || with \norm{.}, e.g.

||a^2 - b^2||^2

to

\norm{a^2 - b^2}^2
REGEXP

M-x query-replace-regexp

||\(.*?\)||

with

\\norm{\1}

The .* matches everything in a greedy way, that means a expression like

emacs - replace numbers with calculated numbers

To replace numbers in a document with other calculated numbers (e.g. to replace a 20 with 20-10=10, and a 43 with 33), the best is to use

M-x query-replace-regexp

which is bound to

M-C-%  (= M-C-Shift-5).

Or use

M-x replace-regepx

E.g. to subtract 8 from each number in  the string

out_11_14Small.png

do the following:

M-x query-replace-regexp
[Query replace regexp:] \([0-9][0-9]\) RET
[Query replace regexp in region \([0-9][0-9\) with:]   \,(+ -8 \#1) RET

RET = press the return key.

emacs - Replace regexp / string / words in several / multiple files

In short:

M-x dired-do-query-replace-regexp

 

Longer version:

To replace the same regexp, string or word in multiple files go into dired mode

C-x C-f RET

Then you should see a list of files.

 

Mark the files you want to edit with m.

To mark all files press t (M-x dired-toogle-marks).