The command `end-of-buffer` uses `(point-max)` to go to the last position in the buffer. If the buffer ends with a newline that will leave you on the empty line at the end -- if you delete that last newline then `end-of-buffer` leaves you at the end of the text in the last line. One possible solution is to advise `end-of-buffer` to just go up a line if it leaves you on an empty line: (advice-add 'end-of-buffer :after (lambda (&rest args) (when (looking-at-p "^$") (previous-line)))) If you want `end-of-buffer` to always leave you at the beginning of the last line of text (rather than at the end if the file has no trailing newline), you might want this instead: (advice-add 'end-of-buffer :after 'end-of-buffer-dwim) (defun end-of-buffer-dwim (&rest args) (when (looking-at-p "^$") (previous-line)) (beginning-of-line))