Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

60%
+1 −0
Q&A Simplest way to change cursor to indicate vim mode

Question What is the simplest way to change the cursor to indicate vim mode when using zsh? Notes I want it to show as a vertical line in insert mode and a block in normal mode. This is the cur...

1 answer  ·  posted 1y ago by mcp‭  ·  last activity 1y ago by GoldenGold‭

Question zsh vim terminal cursor
#3: Post edited by user avatar mcp‭ · 2023-02-08T17:37:49Z (about 1 year ago)
Add headers
  • What is the simplest way to change the cursor to indicate vim mode when using zsh?
  • I want it to show as a vertical line in insert mode and a block in normal mode.
  • This is the current code I am using:
  • ```sh
  • # change cursor shape for different vi modes
  • cursor_mode() {
  • # See https://ttssh2.osdn.jp/manual/4/en/usage/tips/vim.html for cursor shapes
  • cursor_block='\e[2 q'
  • cursor_beam='\e[6 q'
  • function zle-keymap-select {
  • if [[ ${KEYMAP} == vicmd ]] ||
  • [[ $1 = 'block' ]]; then
  • echo -ne $cursor_block
  • elif [[ ${KEYMAP} == main ]] ||
  • [[ ${KEYMAP} == viins ]] ||
  • [[ ${KEYMAP} = '' ]] ||
  • [[ $1 = 'beam' ]]; then
  • echo -ne $cursor_beam
  • fi
  • }
  • zle-line-init() {
  • echo -ne $cursor_beam
  • }
  • zle -N zle-keymap-select
  • zle -N zle-line-init
  • }
  • cursor_mode
  • ```
  • # Question
  • What is the simplest way to change the cursor to indicate vim mode when using zsh?
  • # Notes
  • I want it to show as a vertical line in insert mode and a block in normal mode.
  • This is the current code I am using:
  • ```sh
  • # change cursor shape for different vi modes
  • cursor_mode() {
  • # See https://ttssh2.osdn.jp/manual/4/en/usage/tips/vim.html for cursor shapes
  • cursor_block='\e[2 q'
  • cursor_beam='\e[6 q'
  • function zle-keymap-select {
  • if [[ ${KEYMAP} == vicmd ]] ||
  • [[ $1 = 'block' ]]; then
  • echo -ne $cursor_block
  • elif [[ ${KEYMAP} == main ]] ||
  • [[ ${KEYMAP} == viins ]] ||
  • [[ ${KEYMAP} = '' ]] ||
  • [[ $1 = 'beam' ]]; then
  • echo -ne $cursor_beam
  • fi
  • }
  • zle-line-init() {
  • echo -ne $cursor_beam
  • }
  • zle -N zle-keymap-select
  • zle -N zle-line-init
  • }
  • cursor_mode
  • ```
#2: Post edited by user avatar mcp‭ · 2023-01-30T21:33:24Z (about 1 year ago)
Specify cursor shapes
  • What is the simplest way to change the cursor to indicate vim mode when using zsh?
  • This is the current code I am using:
  • ```sh
  • # change cursor shape for different vi modes
  • cursor_mode() {
  • # See https://ttssh2.osdn.jp/manual/4/en/usage/tips/vim.html for cursor shapes
  • cursor_block='\e[2 q'
  • cursor_beam='\e[6 q'
  • function zle-keymap-select {
  • if [[ ${KEYMAP} == vicmd ]] ||
  • [[ $1 = 'block' ]]; then
  • echo -ne $cursor_block
  • elif [[ ${KEYMAP} == main ]] ||
  • [[ ${KEYMAP} == viins ]] ||
  • [[ ${KEYMAP} = '' ]] ||
  • [[ $1 = 'beam' ]]; then
  • echo -ne $cursor_beam
  • fi
  • }
  • zle-line-init() {
  • echo -ne $cursor_beam
  • }
  • zle -N zle-keymap-select
  • zle -N zle-line-init
  • }
  • cursor_mode
  • ```
  • What is the simplest way to change the cursor to indicate vim mode when using zsh?
  • I want it to show as a vertical line in insert mode and a block in normal mode.
  • This is the current code I am using:
  • ```sh
  • # change cursor shape for different vi modes
  • cursor_mode() {
  • # See https://ttssh2.osdn.jp/manual/4/en/usage/tips/vim.html for cursor shapes
  • cursor_block='\e[2 q'
  • cursor_beam='\e[6 q'
  • function zle-keymap-select {
  • if [[ ${KEYMAP} == vicmd ]] ||
  • [[ $1 = 'block' ]]; then
  • echo -ne $cursor_block
  • elif [[ ${KEYMAP} == main ]] ||
  • [[ ${KEYMAP} == viins ]] ||
  • [[ ${KEYMAP} = '' ]] ||
  • [[ $1 = 'beam' ]]; then
  • echo -ne $cursor_beam
  • fi
  • }
  • zle-line-init() {
  • echo -ne $cursor_beam
  • }
  • zle -N zle-keymap-select
  • zle -N zle-line-init
  • }
  • cursor_mode
  • ```
#1: Initial revision by user avatar mcp‭ · 2023-01-30T21:31:23Z (about 1 year ago)
Simplest way to change cursor to indicate vim mode
What is the simplest way to change the cursor to indicate vim mode when using zsh?

This is the current code I am using:
```sh
# change cursor shape for different vi modes
cursor_mode() {
    # See https://ttssh2.osdn.jp/manual/4/en/usage/tips/vim.html for cursor shapes
    cursor_block='\e[2 q'
    cursor_beam='\e[6 q'
    function zle-keymap-select {
        if [[ ${KEYMAP} == vicmd ]] ||
               [[ $1 = 'block' ]]; then
            echo -ne $cursor_block
        elif [[ ${KEYMAP} == main ]] ||
                 [[ ${KEYMAP} == viins ]] ||
                 [[ ${KEYMAP} = '' ]] ||
                 [[ $1 = 'beam' ]]; then
            echo -ne $cursor_beam
        fi
    }
    zle-line-init() {
        echo -ne $cursor_beam
    }
    zle -N zle-keymap-select
    zle -N zle-line-init
}
cursor_mode
```