How to stop cursor blinking animation in zsh

hello everyone,
I am unable to stop cursor blinking I have disable it in the konsole.when I apply settings the blinking animation stops but as soon as I run another command the animations starts.
I have copied a function from luke smith’s .zshrc for vi mode I think that is making this animations work.
I don’t understand which part to edit please help.
this is my .zshrc

# Use powerline
USE_POWERLINE="false"
# Source manjaro-zsh-configuration
if [[ -e /usr/share/zsh/manjaro-zsh-config ]]; then
  source /usr/share/zsh/manjaro-zsh-config
fi
#PROMPT
#PS1="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b "

PS1="%B%{$fg[red]%}[%{$fg[blue]%}Thundra%{$fg[yellow]%} %{$fg[magenta]%} %~%{$fg[red]%}]%{$reset_color%}$%b "

#autosuggestions
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

export EDITOR=nvim


#aliases
alias nv='nvim'

alias ls='ls --color=auto'
alias grep='grep --colour=auto'
alias egrep='egrep --colour=auto'
alias fgrep='fgrep --colour=auto'

# vi mode
bindkey -v
export KEYTIMEOUT=1

# Enable searching through history
#bindkey '^R' history-incremental-pattern-search-backward

# Edit line in vim buffer ctrl-v
autoload edit-command-line; zle -N edit-command-line
bindkey '^v' edit-command-line
# Enter vim buffer from normal mode
autoload -U edit-command-line && zle -N edit-command-line && bindkey -M vicmd "^v" edit-command-line

# Use vim keys in tab complete menu:
#bindkey -M menuselect 'h' vi-backward-char
#bindkey -M menuselect 'j' vi-down-line-or-history
#bindkey -M menuselect 'k' vi-up-line-or-history
#bindkey -M menuselect 'l' vi-forward-char
#bindkey -M menuselect 'left' vi-backward-char
#bindkey -M menuselect 'down' vi-down-line-or-history
#bindkey -M menuselect 'up' vi-up-line-or-history
#bindkey -M menuselect 'right' vi-forward-char

# Fix backspace bug when switching modes
bindkey "^?" backward-delete-char


# Change cursor shape for different vi modes.
function zle-keymap-select {
  if [[ ${KEYMAP} == vicmd ]] ||
     [[ $1 = 'block' ]]; then
    echo -ne '\e[1 q'
  elif [[ ${KEYMAP} == main ]] ||
       [[ ${KEYMAP} == viins ]] ||
       [[ ${KEYMAP} = '' ]] ||
       [[ $1 = 'beam' ]]; then
    echo -ne '\e[5 q'
  fi
}
zle -N zle-keymap-select
zle-line-init() {
    zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
    echo -ne "\e[5 q"
}
zle -N zle-line-init
echo -ne '\e[5 q' # Use beam shape cursor on startup.
preexec() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt.

Hello,

Check your console profile and disable blinking in Appearance > Cursor

image

it is disabled

as I mentioned here.

Had to have that confirmation … because is important to actually have that on the used profile.

Let me do some other tests on my side.

Update: Can’t seem to reproduce the issue, regardless if using bash or zsh, once i enable the blink in profile settings is enabled, and once i disable it is disabled … so it works as expected.

1 Like

I maybe wrong but I think the cursor blinking part depends on terminal and not the shell.

Just in case, try commenting function zle-keymap-select till the end of the file, you can comment the line by adding # at the start of the line.

Also, after doing it source the .zshrc file by source ~/path_to_.zshrc

yes the cursor did stoped bliking but I want to have this function running so that my cursor changes when I switch vim modes.
https://unix.stackexchange.com/questions/3759/how-to-stop-cursor-from-blinking
I found this discussion but unable to understand being a begginer.:point_up_2:

so a person was having the same problem as me I found this solution don’t know how it solved can anyone explain … I want to know how did it happen. :thinking:
solution :point_down:

Yes, use `'\e[2 q'` (instead of `1` ), and `'\e[6 q'` (instead of `5` ). That'll give you beam and block cursors respectively, without blinking. Mix and match as desired.

Hello, again @shivamChandra65 :slight_smile:

The numbers 2 and 6 are cursor modes or the way that the cursor will be displayed in the terminal.

  • 0: Blinking block
  • 1: Blinking block (default)
  • 2: Steady block (“â–ˆ”)
  • 3: Blinking underline
  • 4: Steady underline (“_”)
  • 5: Blinking bar
  • 6: Steady bar (“|”)

Hope this is sufficient answer.

Off topic and shameless promotion :sweat_smile:
If you like you can try my vim mode, it has more uniform vim experience.
And you don’t have to change the cursor through .zshrc, the prompt will give you indication for the mode i.e. insert or normal (cmd).

4 Likes

that’s awesome I will give it a try.soon …

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.