Hello Alan, Thank you for your response. Apologies for the ambiguous steps. Please find more detailed information below: Here are the steps: 1. Open a file in c++-mode (e.g. emacs -Q test.cc). 2. Add 100 lines of some string (e.g. the word "bar" on every line for 100 lines, no quotes in the actual file): bar bar bar bar ... bar 3. Add a unique string to line 101 (e.g. the word "foo", no quotes in the actual file). bar bar bar bar ... bar foo 4. Close Emacs 5. Open up the file again: emacs -Q test.cc 6. Replace the unique string with some other string: M-x query-replace foo bar 7. You should hit: Args out of range: #, 0, 1 Here's the backtrace when using debug-on-error: Debugger entered--Lisp error: (args-out-of-range # 0 1) buffer-substring-no-properties(0 1) perform-replace("foo" "a" t nil nil nil nil nil nil nil nil) query-replace("foo" "a" nil nil nil nil nil) funcall-interactively(query-replace "foo" "a" nil nil nil nil nil) call-interactively(query-replace nil nil) command-execute(query-replace) I also wanted to add that I tried reproducing with a file that looked like the following, but did NOT see the issue then, either with replacing "foo" (with quotes) or just foo (no quotes): "bar" "bar" "bar" ... "bar" "foo" Even though I'm using "emacs -Q", could it still be interacting with some of the packages I have installed? Here's the list of packages I have installed under $HOME/.emacs.d/elpa: avy-0.3.0 company-20181105.2312 company-lean-20171102.1454 dash-20180910.1856 dash-functional-20180107.1618 epl-20180205.2049 f-20180106.922 flycheck-20181127.1510 gnupg go-mode-1.3.1 haskell-mode-13.16 lean-mode-20180906.1645 pkg-info-20150517.1143 rust-mode-20181008.1628 s-20180406.808 Best, Jayden On Sat, Jun 22, 2019 at 6:25 AM Alan Mackenzie wrote: > Hello, Jayden. > > In article you wrote: > > [-- text/plain, encoding 7bit, charset: UTF-8, 97 lines --] > > [ .... ] > > > Fill a *.cc file with 100 lines of any string (e.g. "bar"). At line 101 > > write a unique string (e.g. "foo"). > > Does your file look like: > > bar > bar > bar > ... > ... > bar > foo > > ? Or does it look like: > > "bar" > "bar" > "bar" > ... > ... > "bar" > "foo" > > ? > > > Close the file and reopen (emacs -Q). > > OK. > > > and perform search-and-replace on "foo" (replacing with any other > string). > > What, precisely, did you do to attempt this "search-and-replace"? With > emacs-26.2, after emacs -Q, I did > > C-x C-f test.cc > > , followed by > > M-% foo FOO > > , in both possibilities for the file (see above), yet could not > reproduce the error. The replacement command simply worked for me. > > > At this point you should see "Args out of range: #, 0, > 1". > > This is what I don't see. :-( At least, not yet. > > [ .... ] > > -- > Alan Mackenzie (Nuremberg, Germany). > >