emacs Basic Keybindings Search and Replace


In Emacs, basic search tool (I-Search) allows you to search after or before the location of your cursor.

  • To search for sometext after the location of your cursor (search-forward) hit C-s sometext. If you want to go to the next occurence of sometext, just press C-s again (and so on for the next occurences). When cursor lands in the right location, press Enter to exit the search prompt.

  • To search before the location of your cursor (search-backward), use C-r the same way you used before.

  • To switch from search-backward to search-forward, press 2 times C-s. And press 2 times C-r to search backward when you're in search-forward prompt.

  • Search and replace:

    M-% (or Esc-% ) oldtext Enter newtext Enter

    • Confirm: y
    • Skip: n
    • Quit: q
    • Replace all: !