This is a very basic tip, but is something we’ll come back to and build on.
To search for text in the buffer, use
C-s and start typing a string to search forwards and
C-r to search backwards. Repeatedly pressing
C-r will move to the next/previous match.
A useful extra tip is that pressing
C-r for a second time before entering your search string will reuse the previous search string.
In emacs, searching is useful finding occurrences of a string in a buffer, but also moving the cursor to a different place in the buffer to continue editing. For example, I might decide I wanted to move the cursor to the end of the word “repeatedly” in the first paragraph to make an edit. I can get their using e.g.
C-r edly and hitting
C-r a couple of times to move to that point. I then hit
RET to end the search and the cursor is where I want it to be.
Remember that you can always use
C-u C-SPACE to jump back to where you started you search after you are finished.
There are a lot of more advanced packages for searching and jumping around the buffer, and we’ll come to those in due course…
M-} to move forward or backward by paragraph.
M-h to mark (highlight) the current paragraph.
When you mark text using
C-SPACE as described previously, emacs adds that location to the “mark ring”. This is just a list of places you have marked previously in a buffer. You can jump to the last place in the mark ring using
C-u C-SPACE, then use
C-u C-SPACE to keep going to previous places.
The neat thing is that emacs automatically adds marks for you when you do different things that jump you to a different place in a buffer (e.g. when you start a search or move to the start or end of the buffer) so
C-u C-SPACE will often magically take you back to where you want to go. Try it – you’ll be surprised how often just does what you want.
If you know you will want to come back to a particular spot, just hit
C-SPACE twice to mark that point.
Reader Clément pointed out that my previous advice to use
C-SPACE to continue cycling through the mark ring doesn’t work with default settings. Instead you should use
C-u C-SPACE to keep moving back through the mark ring. If you want to be able to just use
C-SPACE then you need to customise the variable
set-mark-command-repeat-pop to be non-nil. See the emacs manual.
To move to the start of a line use
C-a and to move to the end of a line, use
To move to the start or end of a sentence, use
M-e respectively. Note that by default, emacs assumes sentences are broken up by a full stop and then two spaces. If you want it to recognise full stop followed by a single space as the end of a sentence then add the following to your emacs config file:
;; sentences end with single space
(setq sentence-end-double-space nil)
Note that this will lead emacs to get a bit confused about abbreviations e.g. that one just there.
To move forward by one word use
M-f, to move back by one word, use
M-> to move to the start or end of a buffer, respectively.