How do I check if Vim is currently recording a macro?
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
Is there a way to programmatically check if Vim is currently in the recording mode triggered by q?
vimscript macro
add a comment |Â
up vote
5
down vote
favorite
Is there a way to programmatically check if Vim is currently in the recording mode triggered by q?
vimscript macro
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
Is there a way to programmatically check if Vim is currently in the recording mode triggered by q?
vimscript macro
Is there a way to programmatically check if Vim is currently in the recording mode triggered by q?
vimscript macro
edited Aug 7 at 2:07
Peter Mortensen
1626
1626
asked Aug 6 at 10:12
wengwengweng
508
508
add a comment |Â
add a comment |Â
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.
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
add a comment |Â
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.
1
I'm curious. Why have you preferred to define an autocommand to initialize the global variable instead of setting it in the vimrc? (withlet 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
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
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.
1
I'm curious. Why have you preferred to define an autocommand to initialize the global variable instead of setting it in the vimrc? (withlet 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
add a comment |Â
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.
1
I'm curious. Why have you preferred to define an autocommand to initialize the global variable instead of setting it in the vimrc? (withlet 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
add a comment |Â
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.
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.
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? (withlet 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
add a comment |Â
1
I'm curious. Why have you preferred to define an autocommand to initialize the global variable instead of setting it in the vimrc? (withlet 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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password