How to set and determine the command line mode of the bash?











up vote
6
down vote

favorite
2












How to set the vi or emacs command line editing mode the Bash AND how to determine which mode is currently set?










share|improve this question







New contributor




Blcknx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    6
    down vote

    favorite
    2












    How to set the vi or emacs command line editing mode the Bash AND how to determine which mode is currently set?










    share|improve this question







    New contributor




    Blcknx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      6
      down vote

      favorite
      2









      up vote
      6
      down vote

      favorite
      2






      2





      How to set the vi or emacs command line editing mode the Bash AND how to determine which mode is currently set?










      share|improve this question







      New contributor




      Blcknx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      How to set the vi or emacs command line editing mode the Bash AND how to determine which mode is currently set?







      bash emacs vi






      share|improve this question







      New contributor




      Blcknx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Blcknx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Blcknx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 6 hours ago









      Blcknx

      1335




      1335




      New contributor




      Blcknx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Blcknx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Blcknx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          11
          down vote



          accepted










          To set:



          set -o vi


          Or:



          set -o emacs


          (setting one unsets the other. You can do set -o vi +o vi to unset both)



          To check:



          if [[ -o emacs ]]; then
          echo emacs mode
          elif [[ -o vi ]]; then
          echo vi mode
          else
          echo neither
          fi


          That syntax comes from ksh. The set -o vi is POSIX. set -o emacs is not (as Richard Stallman objected to the emacs mode being specified by POSIX) but very common among shell implementations. Some shells support extra editing modes. [[ -o option ]] is not POSIX, but supported by ksh, bash and zsh. [ -o option ] is supported by bash, ksh and yash (note that -o is also a binary OR operator for [).






          share|improve this answer























          • It works and it is surprising, that it is that difficult to determine the mode.
            – Blcknx
            6 hours ago






          • 2




            set -o | egrep -w '^emacs|vi' will return whether emacs or vi is set.
            – Stephen Harris
            6 hours ago


















          up vote
          1
          down vote













          There is also bind -V | grep editing-mode.



          man bash is huge but well worth reading in depth.






          share|improve this answer




























            up vote
            0
            down vote













            Since your question is specific about bash:



            To set it permanently for every new session:



            echo 'set -o vi' >> ~/.bashrc


            or (recommended), add (or change) a line in ./inputrc:



            set editing-mode vi


            This will set the editing mode of readline which is used by several other programs beside bash.



            It is easy to unset both options:



            shopt -ou vi emacs


            To set one, either:



            set -o vi


            Or



            shopt -os vi


            The same for emacs. Setting vi unsets emacs and viceversa.



            To list the state:



            $ shopt -op emacs
            set +o emacs

            $ shopt -op vi
            set -o vi


            Or both at once:



            $ shopt -op emacs vi
            set +o emacs
            set -o vi


            To test if vi is set:



            shopt -oq vi      &&   echo vi is set


            Or (ksh syntax):



            [[ -o vi ]]        &&   echo vi is set


            emacs:



            shopt -oq emacs   &&   echo emacs is set


            Or:



            [[ -o emacs ]]    &&   echo emacs is set


            or, to test that no option is set:



            ! ( shopt -oq emacs || shopt -oq vi ) && echo no option is set





            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: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });






              Blcknx is a new contributor. Be nice, and check out our Code of Conduct.










              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f484997%2fhow-to-set-and-determine-the-command-line-mode-of-the-bash%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              11
              down vote



              accepted










              To set:



              set -o vi


              Or:



              set -o emacs


              (setting one unsets the other. You can do set -o vi +o vi to unset both)



              To check:



              if [[ -o emacs ]]; then
              echo emacs mode
              elif [[ -o vi ]]; then
              echo vi mode
              else
              echo neither
              fi


              That syntax comes from ksh. The set -o vi is POSIX. set -o emacs is not (as Richard Stallman objected to the emacs mode being specified by POSIX) but very common among shell implementations. Some shells support extra editing modes. [[ -o option ]] is not POSIX, but supported by ksh, bash and zsh. [ -o option ] is supported by bash, ksh and yash (note that -o is also a binary OR operator for [).






              share|improve this answer























              • It works and it is surprising, that it is that difficult to determine the mode.
                – Blcknx
                6 hours ago






              • 2




                set -o | egrep -w '^emacs|vi' will return whether emacs or vi is set.
                – Stephen Harris
                6 hours ago















              up vote
              11
              down vote



              accepted










              To set:



              set -o vi


              Or:



              set -o emacs


              (setting one unsets the other. You can do set -o vi +o vi to unset both)



              To check:



              if [[ -o emacs ]]; then
              echo emacs mode
              elif [[ -o vi ]]; then
              echo vi mode
              else
              echo neither
              fi


              That syntax comes from ksh. The set -o vi is POSIX. set -o emacs is not (as Richard Stallman objected to the emacs mode being specified by POSIX) but very common among shell implementations. Some shells support extra editing modes. [[ -o option ]] is not POSIX, but supported by ksh, bash and zsh. [ -o option ] is supported by bash, ksh and yash (note that -o is also a binary OR operator for [).






              share|improve this answer























              • It works and it is surprising, that it is that difficult to determine the mode.
                – Blcknx
                6 hours ago






              • 2




                set -o | egrep -w '^emacs|vi' will return whether emacs or vi is set.
                – Stephen Harris
                6 hours ago













              up vote
              11
              down vote



              accepted







              up vote
              11
              down vote



              accepted






              To set:



              set -o vi


              Or:



              set -o emacs


              (setting one unsets the other. You can do set -o vi +o vi to unset both)



              To check:



              if [[ -o emacs ]]; then
              echo emacs mode
              elif [[ -o vi ]]; then
              echo vi mode
              else
              echo neither
              fi


              That syntax comes from ksh. The set -o vi is POSIX. set -o emacs is not (as Richard Stallman objected to the emacs mode being specified by POSIX) but very common among shell implementations. Some shells support extra editing modes. [[ -o option ]] is not POSIX, but supported by ksh, bash and zsh. [ -o option ] is supported by bash, ksh and yash (note that -o is also a binary OR operator for [).






              share|improve this answer














              To set:



              set -o vi


              Or:



              set -o emacs


              (setting one unsets the other. You can do set -o vi +o vi to unset both)



              To check:



              if [[ -o emacs ]]; then
              echo emacs mode
              elif [[ -o vi ]]; then
              echo vi mode
              else
              echo neither
              fi


              That syntax comes from ksh. The set -o vi is POSIX. set -o emacs is not (as Richard Stallman objected to the emacs mode being specified by POSIX) but very common among shell implementations. Some shells support extra editing modes. [[ -o option ]] is not POSIX, but supported by ksh, bash and zsh. [ -o option ] is supported by bash, ksh and yash (note that -o is also a binary OR operator for [).







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 6 hours ago

























              answered 6 hours ago









              Stéphane Chazelas

              295k54558900




              295k54558900












              • It works and it is surprising, that it is that difficult to determine the mode.
                – Blcknx
                6 hours ago






              • 2




                set -o | egrep -w '^emacs|vi' will return whether emacs or vi is set.
                – Stephen Harris
                6 hours ago


















              • It works and it is surprising, that it is that difficult to determine the mode.
                – Blcknx
                6 hours ago






              • 2




                set -o | egrep -w '^emacs|vi' will return whether emacs or vi is set.
                – Stephen Harris
                6 hours ago
















              It works and it is surprising, that it is that difficult to determine the mode.
              – Blcknx
              6 hours ago




              It works and it is surprising, that it is that difficult to determine the mode.
              – Blcknx
              6 hours ago




              2




              2




              set -o | egrep -w '^emacs|vi' will return whether emacs or vi is set.
              – Stephen Harris
              6 hours ago




              set -o | egrep -w '^emacs|vi' will return whether emacs or vi is set.
              – Stephen Harris
              6 hours ago












              up vote
              1
              down vote













              There is also bind -V | grep editing-mode.



              man bash is huge but well worth reading in depth.






              share|improve this answer

























                up vote
                1
                down vote













                There is also bind -V | grep editing-mode.



                man bash is huge but well worth reading in depth.






                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  There is also bind -V | grep editing-mode.



                  man bash is huge but well worth reading in depth.






                  share|improve this answer












                  There is also bind -V | grep editing-mode.



                  man bash is huge but well worth reading in depth.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 2 hours ago









                  studog

                  22316




                  22316






















                      up vote
                      0
                      down vote













                      Since your question is specific about bash:



                      To set it permanently for every new session:



                      echo 'set -o vi' >> ~/.bashrc


                      or (recommended), add (or change) a line in ./inputrc:



                      set editing-mode vi


                      This will set the editing mode of readline which is used by several other programs beside bash.



                      It is easy to unset both options:



                      shopt -ou vi emacs


                      To set one, either:



                      set -o vi


                      Or



                      shopt -os vi


                      The same for emacs. Setting vi unsets emacs and viceversa.



                      To list the state:



                      $ shopt -op emacs
                      set +o emacs

                      $ shopt -op vi
                      set -o vi


                      Or both at once:



                      $ shopt -op emacs vi
                      set +o emacs
                      set -o vi


                      To test if vi is set:



                      shopt -oq vi      &&   echo vi is set


                      Or (ksh syntax):



                      [[ -o vi ]]        &&   echo vi is set


                      emacs:



                      shopt -oq emacs   &&   echo emacs is set


                      Or:



                      [[ -o emacs ]]    &&   echo emacs is set


                      or, to test that no option is set:



                      ! ( shopt -oq emacs || shopt -oq vi ) && echo no option is set





                      share|improve this answer



























                        up vote
                        0
                        down vote













                        Since your question is specific about bash:



                        To set it permanently for every new session:



                        echo 'set -o vi' >> ~/.bashrc


                        or (recommended), add (or change) a line in ./inputrc:



                        set editing-mode vi


                        This will set the editing mode of readline which is used by several other programs beside bash.



                        It is easy to unset both options:



                        shopt -ou vi emacs


                        To set one, either:



                        set -o vi


                        Or



                        shopt -os vi


                        The same for emacs. Setting vi unsets emacs and viceversa.



                        To list the state:



                        $ shopt -op emacs
                        set +o emacs

                        $ shopt -op vi
                        set -o vi


                        Or both at once:



                        $ shopt -op emacs vi
                        set +o emacs
                        set -o vi


                        To test if vi is set:



                        shopt -oq vi      &&   echo vi is set


                        Or (ksh syntax):



                        [[ -o vi ]]        &&   echo vi is set


                        emacs:



                        shopt -oq emacs   &&   echo emacs is set


                        Or:



                        [[ -o emacs ]]    &&   echo emacs is set


                        or, to test that no option is set:



                        ! ( shopt -oq emacs || shopt -oq vi ) && echo no option is set





                        share|improve this answer

























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          Since your question is specific about bash:



                          To set it permanently for every new session:



                          echo 'set -o vi' >> ~/.bashrc


                          or (recommended), add (or change) a line in ./inputrc:



                          set editing-mode vi


                          This will set the editing mode of readline which is used by several other programs beside bash.



                          It is easy to unset both options:



                          shopt -ou vi emacs


                          To set one, either:



                          set -o vi


                          Or



                          shopt -os vi


                          The same for emacs. Setting vi unsets emacs and viceversa.



                          To list the state:



                          $ shopt -op emacs
                          set +o emacs

                          $ shopt -op vi
                          set -o vi


                          Or both at once:



                          $ shopt -op emacs vi
                          set +o emacs
                          set -o vi


                          To test if vi is set:



                          shopt -oq vi      &&   echo vi is set


                          Or (ksh syntax):



                          [[ -o vi ]]        &&   echo vi is set


                          emacs:



                          shopt -oq emacs   &&   echo emacs is set


                          Or:



                          [[ -o emacs ]]    &&   echo emacs is set


                          or, to test that no option is set:



                          ! ( shopt -oq emacs || shopt -oq vi ) && echo no option is set





                          share|improve this answer














                          Since your question is specific about bash:



                          To set it permanently for every new session:



                          echo 'set -o vi' >> ~/.bashrc


                          or (recommended), add (or change) a line in ./inputrc:



                          set editing-mode vi


                          This will set the editing mode of readline which is used by several other programs beside bash.



                          It is easy to unset both options:



                          shopt -ou vi emacs


                          To set one, either:



                          set -o vi


                          Or



                          shopt -os vi


                          The same for emacs. Setting vi unsets emacs and viceversa.



                          To list the state:



                          $ shopt -op emacs
                          set +o emacs

                          $ shopt -op vi
                          set -o vi


                          Or both at once:



                          $ shopt -op emacs vi
                          set +o emacs
                          set -o vi


                          To test if vi is set:



                          shopt -oq vi      &&   echo vi is set


                          Or (ksh syntax):



                          [[ -o vi ]]        &&   echo vi is set


                          emacs:



                          shopt -oq emacs   &&   echo emacs is set


                          Or:



                          [[ -o emacs ]]    &&   echo emacs is set


                          or, to test that no option is set:



                          ! ( shopt -oq emacs || shopt -oq vi ) && echo no option is set






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 1 hour ago

























                          answered 2 hours ago









                          Isaac

                          9,84111445




                          9,84111445






















                              Blcknx is a new contributor. Be nice, and check out our Code of Conduct.










                              draft saved

                              draft discarded


















                              Blcknx is a new contributor. Be nice, and check out our Code of Conduct.













                              Blcknx is a new contributor. Be nice, and check out our Code of Conduct.












                              Blcknx is a new contributor. Be nice, and check out our Code of Conduct.
















                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f484997%2fhow-to-set-and-determine-the-command-line-mode-of-the-bash%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                              Calculate evaluation metrics using cross_val_predict sklearn

                              Insert data from modal to MySQL (multiple modal on website)