Changing cursor style based on mode in both zsh and vim

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite
1












I use vi-mode in oh-my-zsh with the af-magic theme.



I want the cursor style to indicate whether I am in normal mode (block) or insert mode (beam), both in zsh and in vim.



This is what I have so far:



In my ~/.zshrc:



 # vim mode config
# ---------------

# Activate vim mode.
bindkey -v

# Remove mode switching delay.
KEYTIMEOUT=5

# Change cursor shape for different vi modes.
function zle-keymap-select
[[ $KEYMAP == viins ]]
zle -N zle-keymap-select

# Use beam shape cursor on startup.
echo -ne 'e[5 q'

# Use beam shape cursor for each new prompt.
preexec()
echo -ne 'e[5 q'



As found here.



In vim, I use Vundle and terminus.



With these configurations, both zsh and vim work as they should when considered independently.
However, when I enter vim from zsh in insert mode, vim starts in normal mode (as it should) but still shows the beam shape cursor.
Similarly, when I exit vim, I get back to zsh in insert mode, but the cursor is still in block shape (since the last mode in vim was normal).



When after this, I switch modes for the first time (in both zsh and vim), the cursor behaves the way it should again.



How can I make them display the correct cursor after entering and exiting vim as well?



I tried putting



 autocmd VimEnter * stopinsert
autocmd VimLeave * startinsert


in my ~.vimrc, but this does not affect the cursor.







share|improve this question


























    up vote
    3
    down vote

    favorite
    1












    I use vi-mode in oh-my-zsh with the af-magic theme.



    I want the cursor style to indicate whether I am in normal mode (block) or insert mode (beam), both in zsh and in vim.



    This is what I have so far:



    In my ~/.zshrc:



     # vim mode config
    # ---------------

    # Activate vim mode.
    bindkey -v

    # Remove mode switching delay.
    KEYTIMEOUT=5

    # Change cursor shape for different vi modes.
    function zle-keymap-select
    [[ $KEYMAP == viins ]]
    zle -N zle-keymap-select

    # Use beam shape cursor on startup.
    echo -ne 'e[5 q'

    # Use beam shape cursor for each new prompt.
    preexec()
    echo -ne 'e[5 q'



    As found here.



    In vim, I use Vundle and terminus.



    With these configurations, both zsh and vim work as they should when considered independently.
    However, when I enter vim from zsh in insert mode, vim starts in normal mode (as it should) but still shows the beam shape cursor.
    Similarly, when I exit vim, I get back to zsh in insert mode, but the cursor is still in block shape (since the last mode in vim was normal).



    When after this, I switch modes for the first time (in both zsh and vim), the cursor behaves the way it should again.



    How can I make them display the correct cursor after entering and exiting vim as well?



    I tried putting



     autocmd VimEnter * stopinsert
    autocmd VimLeave * startinsert


    in my ~.vimrc, but this does not affect the cursor.







    share|improve this question
























      up vote
      3
      down vote

      favorite
      1









      up vote
      3
      down vote

      favorite
      1






      1





      I use vi-mode in oh-my-zsh with the af-magic theme.



      I want the cursor style to indicate whether I am in normal mode (block) or insert mode (beam), both in zsh and in vim.



      This is what I have so far:



      In my ~/.zshrc:



       # vim mode config
      # ---------------

      # Activate vim mode.
      bindkey -v

      # Remove mode switching delay.
      KEYTIMEOUT=5

      # Change cursor shape for different vi modes.
      function zle-keymap-select
      [[ $KEYMAP == viins ]]
      zle -N zle-keymap-select

      # Use beam shape cursor on startup.
      echo -ne 'e[5 q'

      # Use beam shape cursor for each new prompt.
      preexec()
      echo -ne 'e[5 q'



      As found here.



      In vim, I use Vundle and terminus.



      With these configurations, both zsh and vim work as they should when considered independently.
      However, when I enter vim from zsh in insert mode, vim starts in normal mode (as it should) but still shows the beam shape cursor.
      Similarly, when I exit vim, I get back to zsh in insert mode, but the cursor is still in block shape (since the last mode in vim was normal).



      When after this, I switch modes for the first time (in both zsh and vim), the cursor behaves the way it should again.



      How can I make them display the correct cursor after entering and exiting vim as well?



      I tried putting



       autocmd VimEnter * stopinsert
      autocmd VimLeave * startinsert


      in my ~.vimrc, but this does not affect the cursor.







      share|improve this question














      I use vi-mode in oh-my-zsh with the af-magic theme.



      I want the cursor style to indicate whether I am in normal mode (block) or insert mode (beam), both in zsh and in vim.



      This is what I have so far:



      In my ~/.zshrc:



       # vim mode config
      # ---------------

      # Activate vim mode.
      bindkey -v

      # Remove mode switching delay.
      KEYTIMEOUT=5

      # Change cursor shape for different vi modes.
      function zle-keymap-select
      [[ $KEYMAP == viins ]]
      zle -N zle-keymap-select

      # Use beam shape cursor on startup.
      echo -ne 'e[5 q'

      # Use beam shape cursor for each new prompt.
      preexec()
      echo -ne 'e[5 q'



      As found here.



      In vim, I use Vundle and terminus.



      With these configurations, both zsh and vim work as they should when considered independently.
      However, when I enter vim from zsh in insert mode, vim starts in normal mode (as it should) but still shows the beam shape cursor.
      Similarly, when I exit vim, I get back to zsh in insert mode, but the cursor is still in block shape (since the last mode in vim was normal).



      When after this, I switch modes for the first time (in both zsh and vim), the cursor behaves the way it should again.



      How can I make them display the correct cursor after entering and exiting vim as well?



      I tried putting



       autocmd VimEnter * stopinsert
      autocmd VimLeave * startinsert


      in my ~.vimrc, but this does not affect the cursor.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 20:32









      αғsнιη

      14.8k82462




      14.8k82462










      asked Mar 24 at 15:15









      maddingl

      386




      386




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          I have found a solution:



          I put this in my ~/.vimrc:



          autocmd VimEnter * silent exec "! echo -ne 'e[1 q'"
          autocmd VimLeave * silent exec "! echo -ne 'e[5 q'"





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f433273%2fchanging-cursor-style-based-on-mode-in-both-zsh-and-vim%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            I have found a solution:



            I put this in my ~/.vimrc:



            autocmd VimEnter * silent exec "! echo -ne 'e[1 q'"
            autocmd VimLeave * silent exec "! echo -ne 'e[5 q'"





            share|improve this answer
























              up vote
              1
              down vote



              accepted










              I have found a solution:



              I put this in my ~/.vimrc:



              autocmd VimEnter * silent exec "! echo -ne 'e[1 q'"
              autocmd VimLeave * silent exec "! echo -ne 'e[5 q'"





              share|improve this answer






















                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                I have found a solution:



                I put this in my ~/.vimrc:



                autocmd VimEnter * silent exec "! echo -ne 'e[1 q'"
                autocmd VimLeave * silent exec "! echo -ne 'e[5 q'"





                share|improve this answer












                I have found a solution:



                I put this in my ~/.vimrc:



                autocmd VimEnter * silent exec "! echo -ne 'e[1 q'"
                autocmd VimLeave * silent exec "! echo -ne 'e[5 q'"






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 24 at 20:28









                maddingl

                386




                386






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f433273%2fchanging-cursor-style-based-on-mode-in-both-zsh-and-vim%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?