Is there a way to programmatically check if Vim is currently in the recording mode triggered by q?
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.
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
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
Then you remap q to toggle the value of
g:isRecording when it toggles the recording mode and you can then test
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.