Conditional window split

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











up vote
2
down vote

favorite












I have line to split window at start:



au VimEnter * vsplit


But sometimes it's annoying because I'm opening vim in small terminal, in this case I'd like to not split my window. I've tried this construction but it's not executing at start



if winwidth('%') >= 100
au VimEnter * vsplit
endif


Is there a way to execute spit window depending on window size?










share|improve this question



























    up vote
    2
    down vote

    favorite












    I have line to split window at start:



    au VimEnter * vsplit


    But sometimes it's annoying because I'm opening vim in small terminal, in this case I'd like to not split my window. I've tried this construction but it's not executing at start



    if winwidth('%') >= 100
    au VimEnter * vsplit
    endif


    Is there a way to execute spit window depending on window size?










    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I have line to split window at start:



      au VimEnter * vsplit


      But sometimes it's annoying because I'm opening vim in small terminal, in this case I'd like to not split my window. I've tried this construction but it's not executing at start



      if winwidth('%') >= 100
      au VimEnter * vsplit
      endif


      Is there a way to execute spit window depending on window size?










      share|improve this question















      I have line to split window at start:



      au VimEnter * vsplit


      But sometimes it's annoying because I'm opening vim in small terminal, in this case I'd like to not split my window. I've tried this construction but it's not executing at start



      if winwidth('%') >= 100
      au VimEnter * vsplit
      endif


      Is there a way to execute spit window depending on window size?







      neovim vim-windows






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 19 at 20:08

























      asked Sep 19 at 9:57









      megas

      1546




      1546




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          7
          down vote



          accepted










          Try moving the if into the autocommand:



          au VimEnter * if winwidth('%') >= 100 | vsplit | endif





          share|improve this answer



























            up vote
            6
            down vote













            You need to check the 'winwidth' result at the time the hook is run, not when it's defined. You can do this by putting it in a new function and calling that from the hook:



            function Widevsplit()
            if winwidth('%') >= 100
            vsplit
            endif
            endfunction

            au VimEnter * call Widevsplit()





            share|improve this answer




















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "599"
              ;
              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%2fvi.stackexchange.com%2fquestions%2f17418%2fconditional-window-split%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              7
              down vote



              accepted










              Try moving the if into the autocommand:



              au VimEnter * if winwidth('%') >= 100 | vsplit | endif





              share|improve this answer
























                up vote
                7
                down vote



                accepted










                Try moving the if into the autocommand:



                au VimEnter * if winwidth('%') >= 100 | vsplit | endif





                share|improve this answer






















                  up vote
                  7
                  down vote



                  accepted







                  up vote
                  7
                  down vote



                  accepted






                  Try moving the if into the autocommand:



                  au VimEnter * if winwidth('%') >= 100 | vsplit | endif





                  share|improve this answer












                  Try moving the if into the autocommand:



                  au VimEnter * if winwidth('%') >= 100 | vsplit | endif






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 19 at 10:23









                  Rich

                  13.6k11763




                  13.6k11763




















                      up vote
                      6
                      down vote













                      You need to check the 'winwidth' result at the time the hook is run, not when it's defined. You can do this by putting it in a new function and calling that from the hook:



                      function Widevsplit()
                      if winwidth('%') >= 100
                      vsplit
                      endif
                      endfunction

                      au VimEnter * call Widevsplit()





                      share|improve this answer
























                        up vote
                        6
                        down vote













                        You need to check the 'winwidth' result at the time the hook is run, not when it's defined. You can do this by putting it in a new function and calling that from the hook:



                        function Widevsplit()
                        if winwidth('%') >= 100
                        vsplit
                        endif
                        endfunction

                        au VimEnter * call Widevsplit()





                        share|improve this answer






















                          up vote
                          6
                          down vote










                          up vote
                          6
                          down vote









                          You need to check the 'winwidth' result at the time the hook is run, not when it's defined. You can do this by putting it in a new function and calling that from the hook:



                          function Widevsplit()
                          if winwidth('%') >= 100
                          vsplit
                          endif
                          endfunction

                          au VimEnter * call Widevsplit()





                          share|improve this answer












                          You need to check the 'winwidth' result at the time the hook is run, not when it's defined. You can do this by putting it in a new function and calling that from the hook:



                          function Widevsplit()
                          if winwidth('%') >= 100
                          vsplit
                          endif
                          endfunction

                          au VimEnter * call Widevsplit()






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 19 at 10:22









                          JigglyNaga

                          31826




                          31826



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f17418%2fconditional-window-split%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?