Mac – How to search/replace string for the whole buffer in Emacs without going back to the beginning

emacs

It is really inconvenient to first go back to the buffer top and then do the search/query. Well, for search, it is relatively simple that you can just press C-s one more time to wrap around, but for query/replace, it's tedious.

Any simple hack to do that without going back to the buffer top for both operations?

Best Answer

Huh, looks like you can't (taken from here, emphasis mine):

To replace every instance of 'foo' after point with 'bar', use the command M-x replace-string with the two arguments foo and bar. Replacement occurs only after point, so if you want to cover the whole buffer you must go to the beginning first.

Personally, I split the buffer in two (C-x 2), go to the top (C-Home) and then run the replace command, switch back to my original pane (C-x o) and then kill the second (C-x 0). Don't know if there is a trick to make that simpler.

Related Question