I'm an emacs newbie and am using evil mode for text formatting. I have some text in the following format:

word1 = meaning with elaboration; word2 = simpler meaning; word3; word4 = much long explanation needed; 

and want to wrap each of word1, word2, word3 etc.. into \textif\textbf{word1}}, \textif\textbf{word2}} etc. and transform the original text as

\textif{\textbf{word1}} = meaning with elaboration;
\textif{\textbf{word2}} = simpler meaning;
\textif{\textbf{word4}} = much long explanation needed;

In VIM, I verified separately that the following search+replace pattern applies the changes for word2, word3 and word4 (I know this pattern won't change word1)

:%s,;\s*\(\w*\),; \r\\textit\{\\textbf\{\1\}\},g

However, this doesn't work in emacs. All I see is Ex: Syntax error

Does vim-style search+replace work in emacs? Is there a way to apply the same search+replace in emacs?

  • I cannot reproduce that, neither from my fully customized Emacs setup nor from a minimal Evil setup (run make emacs inside a Git checkout of Evil, decline running tests, C-x b foo.tex, M-x tex-mode, insert the text above, execute the ex command above). In both cases I see "[No match]" and upon executing the commands, I get no replacements. Ensure you're using the latest version and provide a minimal set of reproduction instructions.
    – wasamasa
    Dec 18, 2020 at 10:25
  • Also consider that you have the choice between using Emacs-flavored regex (fast, verbose) and Vim-flavored regex (slow, buggy). Consider using the former to avoid bugs.
    – wasamasa
    Dec 18, 2020 at 10:29

1 Answer 1


Evil's vim-style search-replace does work, but you have to modify it slightly:

:%s/; \(\w+\)/;\n\\textit{\\textbf{\1}}/g will perform the replacement you want (this won't affect word1, but you've already mentioned that).

You have to use / to separate the s, match, replacement and the global g.

\s* doesn't match the whitespace characters as expected.

  • Can someone show me the emacs-way to achieve the same? I've tried 'M-x regex-replace` with a few regular expressions but haven't found a solution yet. My replace-regex ;[:space]+[^[:space]+] doesn't work
    – linuxfan
    Dec 19, 2020 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.