Emacs: Save Cursor Position

By Xah Lee. Date: . Last updated: .

You can save the cursor position for every file you opened. So, next time you open the file, the cursor will be at the position you last opened it.

Put this code in your emacs init file:

;; remember cursor position, for emacs 25.1 or later
(save-place-mode 1)

For before emacs 25.1, the syntax is different. Use this code:

;; remember cursor position
(if (version< emacs-version "25.0")
      (require 'saveplace)
      (setq-default save-place t))
  (save-place-mode 1))

By default, the cursor position info is saved at ~/.emacs.d/places

The file location is controlled by the variable save-place-file.

saveplace.el is written by Karl Fogel since 1993. Karl is also the author of Emacs's Bookmark Feature. 〔►see Emacs: Bookmark〕 Thanks Karl.

Like it? Buy Xah Emacs Tutorial. Thanks.