This answer shows how to position the cursor at an offset of a specified number of characters from the beginning of the buffer, namely by executing M-x goto-char 47
(for an offset of 47 characters from the buffer's beginning). How can I position the cursor at an offset of a specified number of character from the buffer's end?
Asked
Active
Viewed 53 times
0
1 Answers
1
You can achieve that using
(goto-char (- (buffer-size) offset))
Where you replace 'offset' with some number.
(You can run the command using M-:
)
Alternatively, you could first jump to the end of the buffer using M->
end then jump back a certain number of characters using a numerical prefix by pressing C-u 'some-number'
followed by C-b
.

dalanicolai
- 6,108
- 7
- 23
-
Thanks. Is there a way to specify the buffer size as an argument to `goto-char` when using the `M-x-goto-char` version? Say, something along the lines of `M-x-goto-char-(-(buffer-size) 47)`? – Evan Aad Dec 13 '22 at 09:49
-
1Not that I know of. But you can easily [create a custom command](https://www.gnu.org/software/emacs/manual/html_node/elisp/Defining-Commands.html) for it of course. ([here is another link](https://superuser.com/a/194215/919841) to how to create a command). – dalanicolai Dec 13 '22 at 09:52