I got something like that:

(global-set-key [insert] (lambda () (interactive) (overwrite-mode) (setq cursor-type 't)))

But I don't know how to do it so that when you exit the insert mode (when you press insert again) it becomes a bar again.

(setq-default cursor-type 'bar) 
  • The cursor-type is frame-local, not buffer-local. So, changing the cursor-type will change any selected windows displaying a buffer in frame.
    – lawlist
    Commented Sep 10, 2018 at 15:10
  • @lawlist: "frame-local" doesn't exist any more in Emacs-26. cursor-type is a buffer-local variable.
    – Stefan
    Commented Sep 10, 2018 at 15:13

2 Answers 2


Rather than define a new command that you bind to the same key, you'll be better off using the minor mode's hook:

(add-hook 'overwrite-mode-hook
          (lambda ()
            (setq cursor-type (if overwrite-mode t 'bar))))
  • It appears this changes the cursor after getting out of overwrite-mode
    – ychaouche
    Commented Apr 18, 2022 at 11:23

See Changing Cursor Dynamically, which describes library cursor-chg.el.

When a buffer is read-only or is in overwrite mode, the cursor type changes to curchg-overwrite/read-only-cursor-type (by default, box). This is controlled by change-cursor-mode and user option curchg-change-cursor-on-overwrite/read-only-flag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.