33

How do I make the cursor stop blinking when in a TTY? (or anywhere else).

BONUS Points for one universal setting that stops the cursor blinking almost everywhere.

11 Answers 11

33

There is a standard control sequence to turn off cursor blinking on terminals.

printf '\033[?12l'

However many terminals do not implement this setting, so read on.

There is a more widely implemented standard terminal setting for switching cursor visibility between high visibility, normal visibility and invisibility. Some terminals don't make a difference between normal and high, and there's no guarantee that one or the other will or will not blink. In terminfo, emit the cvvis, cnorm or civis string (e.g. tput cvvis). The corresponding termcap entries are vs, ve and vi.

These setting will not survive a terminal reset, so you may find that it doesn't survive the launching of many full-screen applications. You can overcome this difficulty by adding the cursor configuration changing sequence to your terminal's reset string.

  • On a terminfo-based system using ncurses, save your terminal's terminfo settings to a file with infocmp >>~/etc/terminfo.txt. Edit the description to change the rs1 (basic reset) sequence, e.g. replace rs1=\Ec by rs1=\Ec\E[?12l. With some programs and settings, you may need to change the rs2 (full reset) as well. Then compile the terminfo description with tic ~/etc/terminfo.txt (this writes under the directory $TERMINFO, or ~/.terminfo if unset). Or more automatically:
    infocmp -1 | sed '/^.rs[12]=/ s/,$/\\E[?12l,/' | tic -
    
  • On a termcap-based system, grab the termcap settings from your termcap database (typically /etc/termcap). Change the is (basic reset) and rs (full reset) sequences to append your settings, e.g. :is=\Ec\E[?12l:. Set the TERMCAP environment variable to the edited value (beginning and ending with :).

Some terminals and other applications give you more options:

  • The xterm cursor blinks if the cursorBlink resource is set to true or the -bc option is passed on the command line. The blink rate is customizable through the cursorOnTime and cursorOffTime resources.
  • Some other GUI terminal emulators can blink the cursor; check their configuration dialog box.
  • The Linux PC (VGA) console has a number of cursor settings; their exact meaning and applicability depends on the underlying VGA implementation (Linux framebuffer or video card). If your default cursor blinks, try turning the hardware cursor off and the software cursor on with something like printf '\033[17;127?c' (the first parameter 17 gives you the software cursor without a hardware cursor, and the second parameter set to 127 makes it essentially inverse video). See above regarding terminal resets.
  • In Emacs, M-x blink-cursor-mode toggles the cursor's blinking. Put (blink-cursor-mode 0) in your ~/.emacs to turn it off. This is a global setting and does not apply in a text terminal.

See also Juri Linkov (Jurta)'s No Blinking page for how to turn off blinking in Lesstif, Tk, Gtk (Gnome), Qt (KDE), Firefox, and more.

0
20

I found this to be easier if you have root permissions:

~$ echo 0 > /sys/class/graphics/fbcon/cursor_blink

I put it in the machine startup script like /etc/rc.local for arch linux.

1
  • zsh: no such file or directory: /sys/class/graphics/fbcon/cursor_blink
    – alper
    Commented Apr 24, 2023 at 17:01
18

This gives you a solid yellow block (nonblinking) as a cursor:

echo -n -e '\e[?17;14;224c'

For more info check these references: Linuxgazette and EmacsWiki as well as the file /usr/src/linux/Documentation/VGA-softcursor.txt (if present on your system)

4
  • 3
    this works for me until i use vim, then when i exit the cursor is back to blinking :( Commented Sep 28, 2013 at 4:48
  • 1
    And this gives you a non-blinking solid white block echo -e '\033[?16;0;224c'
    – Utku
    Commented Sep 25, 2016 at 10:45
  • thx, I could change the last number (224) to 244 to get a solid white block :)
    – user86041
    Commented May 8, 2017 at 11:20
  • I have no effect of this on my system running bash 5.0.11 on Arch Linux
    – 15 Volts
    Commented Oct 24, 2019 at 5:21
10

This hides completely the cursor.

tput civis

To restore:

tput cnorm
6

In the linux tty you can use the escape sequence "\e[?48;0;64c" or whatever you like but this doesn't work in tmux/vim.

Tmux/Vim issue a cnorm command on startup which by default contains a "\e[?0c". You can see that this undoes the effects of the above setting. You need to change cnorm to the above sequence in order for the TUI applications to reset the cursor to your preference.

More info on this by Gilles but if you are looking for a quick fix try this:

infocmp linux > /tmp/linux-terminfo
# Replace the last escape sequence here with your colors and settings
sed -i 's/cnorm=\\E\[?25h\\E\[?0c/cnorm=\\E[?25h\\E[?48;0;64c/' /tmp/linux-terminfo
tic /tmp/linux-terminfo

The last command will generate the new terminfo under ~/.terminfo which should be picked up automatically if you restart tmux server/vim.

4

Put

\033[?17;0;127c

to your PS1 variable and you'll stop blinking constantly.

E.G:

export PS1='\033[?17;0;127c\u:\w\$ '

1
  • 1
    This will (at least for me) screw up the terminal line breaks (on line overflow). Use square brackets, escaped: For example, BLUEBOXNOBLINK="\033[?17;0;60c", then PS1="\[$BLUEBOXNOBLINK\]\[$BROWN\]\u \[$CYAN\]\W: \[$NC\]" Commented Aug 13, 2012 at 12:21
2

Works in gnome-terminal, Cygwin, etc.

cursor.sh

#! /bin/bash
case $1 in
    bb) echo -en '\e[1 q';; # blinking block
    nb) echo -en '\e[2 q';; # steady block
    bu) echo -en '\e[3 q';; # blinking underline
    nu) echo -en '\e[4 q';; # steady underline
    bv) echo -en '\e[5 q';; # blinking vertical bar
    nv) echo -en '\e[6 q';; # steady vertical bar
     *) echo -en '\e[0 q';; # default user-configured cursor 
esac

[Yes, the Space character is required.]

Source: Console Virtual Terminal Sequences – Windows Console at Microsoft Docs.

0
sudo cp /etc/issue /etc/issue.tmp
setterm -cursor off | sudo tee /etc/issue
cat /etc/issue.tmp | sudo tee --append /etc/issue
sudo rm /etc/issue.tmp
sudo reboot
3
  • It is a wonderful solution and got probably a lot of upvotes, if the author didn't forget to explain it... :-)
    – peterh
    Commented Oct 28, 2014 at 8:59
  • 1
    -cursor off is not quite what is asked for at all, it makes the cursor disappear... setterm -blink off seems more promising, but it affects text, not the actual cursor. Commented Oct 28, 2014 at 9:37
  • setterm -cursor off; setterm -cursor on does work here, but it is an unacceptable workaround
    – Thor
    Commented Oct 10, 2017 at 22:40
0

I was having this problem with the tty blinking cursor too. After looking in various places I eventually found this on GitHub. The cursor has stopped blinking in tty now.

1
  • Please consider explaining or at least summarizing the necessary steps to make this work on the target machine.
    – AdminBee
    Commented Jul 4, 2023 at 10:44
0

For Linux console:

Alternative 1

Add -I "\033[?17;0;255c" option to getty lines in your /etc/inittab file. To do so:

  1. Open the /etc/inittab file with a text editor. There should be lines that contain getty or agetty or similar. An example is:
    tty1::respawn:/sbin/getty 38400 tty1
    
  2. Add -I "\033[?17;0;255c" to each getty line. As an example, after adding -I "\033[?17;0;255c", the getty line above would look as follows:
    tty1::respawn:/sbin/getty -I "\033[?17;0;255c" 38400 tty1
    
  3. Reboot the system, or alternatively, kill all getty processes.

Alternative 2

A better alternative is to put ESC[?17;0;255c in /etc/issue, instead of putting it to getty lines. Doing this using vi is as follows:

  1. Open /etc/issue using vi.
  2. On anywhere of the /etc/issue file, enter insert mode.
  3. While you are in insert mode, press ^V (that is, Ctrlv), then press Esc. The escape character should now be inserted.
  4. Now, insert the remaining characters, which are [?17;0;255c.

Alternative 3

Another alternative is keeping the hardware cursor (instead of using a software cursor) and stop blinking of the hardware cursor and make it a block cursor. To do so:

  1. Add the following to /etc/inittab:
    # Stop cursor blink on Linux console
    ::sysinit:/bin/sh -c "echo 0 > /sys/class/graphics/fbcon/cursor_blink"
    
  2. Add ESC[?8c to /etc/issue. Refer to "Alternative 2" for instructions on doing this.

However, with this option, the cursor does not become bright white. I guess this is only possible with using the software cursor.

After following any of these alternatives, you will obtain a white, non-blinking, block cursor.

Further information

0

I put

echo 0 > /sys/class/graphics/fbcon/cursor_blink

in /etc/rc.local and created a systemd service for it using online instructions. However, I noticed that sometimes after boot the cursor is still blinking. It would be good to know the correct way to permanently turn off cursor blinking via sysfs on a modern systemd system, does anyone have any tips? Some distributions have /etc/sysfs.conf but I am running Arch and don't find this file in sysfsutils or elsewhere.

As a temporary fix I ran the following command

sudo zsh -c 'echo -n "\033[?17;0;255c" >> /etc/issue'

Some experimentation showed that the 255c at the end works better than 127c listed above, it produces a white rather than grey cursor.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .