How do I check if Vim is currently recording a macro?

Multi tool use
Multi tool use

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











up vote
5
down vote

favorite
1












Is there a way to programmatically check if Vim is currently in the recording mode triggered by q?







share|improve this question

























    up vote
    5
    down vote

    favorite
    1












    Is there a way to programmatically check if Vim is currently in the recording mode triggered by q?







    share|improve this question























      up vote
      5
      down vote

      favorite
      1









      up vote
      5
      down vote

      favorite
      1






      1





      Is there a way to programmatically check if Vim is currently in the recording mode triggered by q?







      share|improve this question













      Is there a way to programmatically check if Vim is currently in the recording mode triggered by q?









      share|improve this question












      share|improve this question




      share|improve this question








      edited Aug 7 at 2:07









      Peter Mortensen

      1626




      1626









      asked Aug 6 at 10:12









      wengwengweng

      508




      508




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          13
          down vote



          accepted










          Since Vim 8.1-0020, there is a reg_recording() function that'll return the name of the current register being recorded. An empty string is returned if we are not recording.






          share|improve this answer





















          • That is the correct answer.
            – Christian Brabandt
            Aug 6 at 12:32






          • 2




            @ChristianBrabandt. Well, it depends if the script needs to target older versions of Vim. In that case, statox' solution may be the only workaround available.
            – Luc Hermitte
            Aug 6 at 12:35

















          up vote
          3
          down vote













          Edit I wasn't aware of reg_recording() but if you have a newer version of Vim Luc's answer is clearly the best answer.



          I'm not aware of a built-in way to check if Vim is recording but you could use the following workaround in your .vimrc:



          let g:isRecording = get(g:, 'isRecording', 0)
          nnoremap q :let g:isRecording = !g:isRecording<CR>q


          The first line will create a global variable g:isRecording which is falsy by default or takes its existing value if you re-source your .vimrc.



          Then you remap q to toggle the value of g:isRecording when it toggles the recording mode and you can then test g:isRecording.



          That's not the most elegant solution but as :h recording doesn't seem to mention a variable which would change with q and :h autocmd-events doesn't mention an event related to recording, I guess that the easiest way to do.






          share|improve this answer



















          • 1




            I'm curious. Why have you preferred to define an autocommand to initialize the global variable instead of setting it in the vimrc? (with let g:isRecording = get(g:, 'isRecording', 0) to permit to source the vimrc as many times as we wish)
            – Luc Hermitte
            Aug 6 at 12:01






          • 1




            @LucHermitte It was because I didn't think of resourcing the vimrc :)
            – statox♦
            Aug 6 at 13:33










          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%2f17011%2fhow-do-i-check-if-vim-is-currently-recording-a-macro%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
          13
          down vote



          accepted










          Since Vim 8.1-0020, there is a reg_recording() function that'll return the name of the current register being recorded. An empty string is returned if we are not recording.






          share|improve this answer





















          • That is the correct answer.
            – Christian Brabandt
            Aug 6 at 12:32






          • 2




            @ChristianBrabandt. Well, it depends if the script needs to target older versions of Vim. In that case, statox' solution may be the only workaround available.
            – Luc Hermitte
            Aug 6 at 12:35














          up vote
          13
          down vote



          accepted










          Since Vim 8.1-0020, there is a reg_recording() function that'll return the name of the current register being recorded. An empty string is returned if we are not recording.






          share|improve this answer





















          • That is the correct answer.
            – Christian Brabandt
            Aug 6 at 12:32






          • 2




            @ChristianBrabandt. Well, it depends if the script needs to target older versions of Vim. In that case, statox' solution may be the only workaround available.
            – Luc Hermitte
            Aug 6 at 12:35












          up vote
          13
          down vote



          accepted







          up vote
          13
          down vote



          accepted






          Since Vim 8.1-0020, there is a reg_recording() function that'll return the name of the current register being recorded. An empty string is returned if we are not recording.






          share|improve this answer













          Since Vim 8.1-0020, there is a reg_recording() function that'll return the name of the current register being recorded. An empty string is returned if we are not recording.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Aug 6 at 12:06









          Luc Hermitte

          8,68111124




          8,68111124











          • That is the correct answer.
            – Christian Brabandt
            Aug 6 at 12:32






          • 2




            @ChristianBrabandt. Well, it depends if the script needs to target older versions of Vim. In that case, statox' solution may be the only workaround available.
            – Luc Hermitte
            Aug 6 at 12:35
















          • That is the correct answer.
            – Christian Brabandt
            Aug 6 at 12:32






          • 2




            @ChristianBrabandt. Well, it depends if the script needs to target older versions of Vim. In that case, statox' solution may be the only workaround available.
            – Luc Hermitte
            Aug 6 at 12:35















          That is the correct answer.
          – Christian Brabandt
          Aug 6 at 12:32




          That is the correct answer.
          – Christian Brabandt
          Aug 6 at 12:32




          2




          2




          @ChristianBrabandt. Well, it depends if the script needs to target older versions of Vim. In that case, statox' solution may be the only workaround available.
          – Luc Hermitte
          Aug 6 at 12:35




          @ChristianBrabandt. Well, it depends if the script needs to target older versions of Vim. In that case, statox' solution may be the only workaround available.
          – Luc Hermitte
          Aug 6 at 12:35










          up vote
          3
          down vote













          Edit I wasn't aware of reg_recording() but if you have a newer version of Vim Luc's answer is clearly the best answer.



          I'm not aware of a built-in way to check if Vim is recording but you could use the following workaround in your .vimrc:



          let g:isRecording = get(g:, 'isRecording', 0)
          nnoremap q :let g:isRecording = !g:isRecording<CR>q


          The first line will create a global variable g:isRecording which is falsy by default or takes its existing value if you re-source your .vimrc.



          Then you remap q to toggle the value of g:isRecording when it toggles the recording mode and you can then test g:isRecording.



          That's not the most elegant solution but as :h recording doesn't seem to mention a variable which would change with q and :h autocmd-events doesn't mention an event related to recording, I guess that the easiest way to do.






          share|improve this answer



















          • 1




            I'm curious. Why have you preferred to define an autocommand to initialize the global variable instead of setting it in the vimrc? (with let g:isRecording = get(g:, 'isRecording', 0) to permit to source the vimrc as many times as we wish)
            – Luc Hermitte
            Aug 6 at 12:01






          • 1




            @LucHermitte It was because I didn't think of resourcing the vimrc :)
            – statox♦
            Aug 6 at 13:33














          up vote
          3
          down vote













          Edit I wasn't aware of reg_recording() but if you have a newer version of Vim Luc's answer is clearly the best answer.



          I'm not aware of a built-in way to check if Vim is recording but you could use the following workaround in your .vimrc:



          let g:isRecording = get(g:, 'isRecording', 0)
          nnoremap q :let g:isRecording = !g:isRecording<CR>q


          The first line will create a global variable g:isRecording which is falsy by default or takes its existing value if you re-source your .vimrc.



          Then you remap q to toggle the value of g:isRecording when it toggles the recording mode and you can then test g:isRecording.



          That's not the most elegant solution but as :h recording doesn't seem to mention a variable which would change with q and :h autocmd-events doesn't mention an event related to recording, I guess that the easiest way to do.






          share|improve this answer



















          • 1




            I'm curious. Why have you preferred to define an autocommand to initialize the global variable instead of setting it in the vimrc? (with let g:isRecording = get(g:, 'isRecording', 0) to permit to source the vimrc as many times as we wish)
            – Luc Hermitte
            Aug 6 at 12:01






          • 1




            @LucHermitte It was because I didn't think of resourcing the vimrc :)
            – statox♦
            Aug 6 at 13:33












          up vote
          3
          down vote










          up vote
          3
          down vote









          Edit I wasn't aware of reg_recording() but if you have a newer version of Vim Luc's answer is clearly the best answer.



          I'm not aware of a built-in way to check if Vim is recording but you could use the following workaround in your .vimrc:



          let g:isRecording = get(g:, 'isRecording', 0)
          nnoremap q :let g:isRecording = !g:isRecording<CR>q


          The first line will create a global variable g:isRecording which is falsy by default or takes its existing value if you re-source your .vimrc.



          Then you remap q to toggle the value of g:isRecording when it toggles the recording mode and you can then test g:isRecording.



          That's not the most elegant solution but as :h recording doesn't seem to mention a variable which would change with q and :h autocmd-events doesn't mention an event related to recording, I guess that the easiest way to do.






          share|improve this answer















          Edit I wasn't aware of reg_recording() but if you have a newer version of Vim Luc's answer is clearly the best answer.



          I'm not aware of a built-in way to check if Vim is recording but you could use the following workaround in your .vimrc:



          let g:isRecording = get(g:, 'isRecording', 0)
          nnoremap q :let g:isRecording = !g:isRecording<CR>q


          The first line will create a global variable g:isRecording which is falsy by default or takes its existing value if you re-source your .vimrc.



          Then you remap q to toggle the value of g:isRecording when it toggles the recording mode and you can then test g:isRecording.



          That's not the most elegant solution but as :h recording doesn't seem to mention a variable which would change with q and :h autocmd-events doesn't mention an event related to recording, I guess that the easiest way to do.







          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited Aug 6 at 13:32


























          answered Aug 6 at 11:33









          statox♦

          23.9k556121




          23.9k556121







          • 1




            I'm curious. Why have you preferred to define an autocommand to initialize the global variable instead of setting it in the vimrc? (with let g:isRecording = get(g:, 'isRecording', 0) to permit to source the vimrc as many times as we wish)
            – Luc Hermitte
            Aug 6 at 12:01






          • 1




            @LucHermitte It was because I didn't think of resourcing the vimrc :)
            – statox♦
            Aug 6 at 13:33












          • 1




            I'm curious. Why have you preferred to define an autocommand to initialize the global variable instead of setting it in the vimrc? (with let g:isRecording = get(g:, 'isRecording', 0) to permit to source the vimrc as many times as we wish)
            – Luc Hermitte
            Aug 6 at 12:01






          • 1




            @LucHermitte It was because I didn't think of resourcing the vimrc :)
            – statox♦
            Aug 6 at 13:33







          1




          1




          I'm curious. Why have you preferred to define an autocommand to initialize the global variable instead of setting it in the vimrc? (with let g:isRecording = get(g:, 'isRecording', 0) to permit to source the vimrc as many times as we wish)
          – Luc Hermitte
          Aug 6 at 12:01




          I'm curious. Why have you preferred to define an autocommand to initialize the global variable instead of setting it in the vimrc? (with let g:isRecording = get(g:, 'isRecording', 0) to permit to source the vimrc as many times as we wish)
          – Luc Hermitte
          Aug 6 at 12:01




          1




          1




          @LucHermitte It was because I didn't think of resourcing the vimrc :)
          – statox♦
          Aug 6 at 13:33




          @LucHermitte It was because I didn't think of resourcing the vimrc :)
          – statox♦
          Aug 6 at 13:33












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f17011%2fhow-do-i-check-if-vim-is-currently-recording-a-macro%23new-answer', 'question_page');

          );

          Post as a guest













































































          u,ViF,LfiU5rZW7DeRKhcH8 PS e21xu1Q 8MT,hre KHBPMzD 94lWBOkNxvITK8SfwzvxLZ JP6bv wZtw 80b,W
          OpH anRkmXpIch75TVeHD8I,qvYM,ekz1D,oJ

          Popular posts from this blog

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

          How many registers does an x86_64 CPU actually have?

          Displaying single band from multi-band raster using QGIS