I’m trying to interrupt a for loop such as in code below,
for num in buffer_number_list
" Select the buffer
exe 'buffer' num
" Run the command that's passed as an argument
exe a:command
" Save if necessary
update
endfor
instead of interrupting only line exe a:command, when a:command is a
:s/// command.
The purpose is to change code on response to How to do search & replace with ack in vim?
I’ve tried surrounding the line exe a:command with a try/catch block,
but it doesn’t worked, probably because the command handled the interrupt
signal without re-throwing it.
Tried remapping CTRL-c to change some variable (which would be checked inside of the loop), but it didn’t worked:
let original_Ctrl_c = maparg('<c-c>', 'n')
exe 'nnoremap <c-c> :call <SID>BreakLoop()<CR>' . original_Ctrl_c
It seems that the mapping didn’t trigger when the interrupt signal is
caught.
Any ideas?
EDIT:
It seems that this problem only occurs in gVim (thanks @ib.)
Trying to reproduce the behavior you describe I have constructed the following
test case. It includes two identical files created using the command
and opened in Vim without any initialization apart from sourcing the file
containing implementation of the
:QFDocommand:or
Searching for a pattern in those two files,
populates the contents of the quickfix window that can be used to run the
command in question,
Interrupting this command using Ctrl+C after the first
replacement, which occurs to be in the file
tmp1, terminates the whole:QFDocommand, and therefore the filetmp2remains untouched. This factmeans that the behavior you are trying to overcome is caused by some
.vimrccustomization or plugin. To locate the actual configuration breaking
Ctrl+C behavior, disable all of the plugins and try
enabling them one by one running the above test case each time.