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.

Emacs Show Line/Column Number

  1. Show Line Numbers
  2. Show Cursor Position
  3. Save Cursor Position

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp