43

I would like to change the cursor, like in Terminal, from the block to the I-Beam cursor.

From this:

Block

To this:

Ibeam

How would I do this?

Also, on a side note, how do I change the color of the cursor?

3 Answers 3

61

In order to change your cursor or caret, what you want to do is:

Open your .emacs file and this line of code:

(setq-default cursor-type 'bar) 

And to change the color:

(set-cursor-color "#ffffff") 

Of course, you can change #ffffff to any hexadecimal color.

1
  • 1
    Just saw a lot of pretty colors at kuler but I think your answer is better without the reference.
    – remvee
    Commented Sep 28, 2014 at 17:09
16

Cursor type can be set for a given buffer (using buffer-local variable cursor-type), as indicated in the answer by @King. (That answer uses setq-default to set the default value for all buffers.)

Or it can be set for a given frame, as frame parameter cursor-type.

You can set it the default cursor type for all frames by adding it to option default-frame-alist. For example add this item to the alist: (cursor-type . bar).

Here is a command (from library oneonone.el to set the cursor type for the current frame:

(defun 1on1-set-cursor-type (cursor-type)
  "Set the cursor type of the selected frame to CURSOR-TYPE.
When called interactively, prompt for the type to use.
To get the frame's current cursor type, use `frame-parameters'."
  (interactive
   (list (intern (completing-read
                   "Cursor type: "
                   (mapcar 'list '("box" "hollow" "bar" "hbar" nil))))))
  (modify-frame-parameters (selected-frame) (list (cons 'cursor-type cursor-type))))

Cursor color is always per-frame, not per-buffer.

(In library oneonone.el you will also find options to automatically change the cursor type when you switch a buffer between read-only and writable, or between overwrite mode and insert mode, or to change the type to a box cursor (more noticeable) when Emacs is idle.)

1

Unfortunately I can't comment yet, but I also tried to change the color by adding the command (set-cursor-color "#ffff00"). When I reload my emacs, I don't get it to work though. The cursor is still white (not as expected: yellow). I used the M-x eval-buffer and for a fraction of a second my cursor got yellow and returned to white shortly afterwards. What is the problem there?

EDIT: I use evil-mode and because they handle it differently, you can copy this and customize it in a way you want. I copied this from the website @g-gundam provided.

(setq          evil-default-cursor       '("DodgerBlue1" box)
              evil-normal-state-cursor  '("gray" box)
              evil-emacs-state-cursor   '("orange" box)
              evil-motion-state-cursor  '("SeaGreen1" box)
              evil-insert-state-cursor  '("white" bar)
              evil-visual-state-cursor  '("white" hbar)
              evil-replace-state-cursor '("pink" hbar))
4
  • 1
    Are you using evil-mode by any chance? It has its own cursor color control. old.reddit.com/r/emacs/comments/71czre/…
    – g-gundam
    Commented May 16, 2023 at 14:16
  • 1
    Yes I use emacs-evil. This worked as well for me. Thanks for helping me out... (again) :^) Commented May 16, 2023 at 14:33
  • You could add value to your answer by describing the solution provided by @g-gundam. Commented May 16, 2023 at 17:13
  • @FranBurstall Sure! I edited my response :) Commented May 16, 2023 at 18:17

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.