I would like to change the cursor, like in Terminal, from the block to the I-Beam cursor.
From this:
To this:
How would I do this?
Also, on a side note, how do I change the color of the cursor?
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.
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.)
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))