:h :cdo says:
When an error is detected execution stops.
The last buffer (or where an error occurred) becomes
the current buffer.
Let's see what really happens:
Prepare test file a:
dog0 dog1
dog2 dog3
Prepare test file b:
dog4 dog5
dog6 dog7
set up quickfix for all dogs :
vimgrep /dog\d/g a b
Create a test command:
" call cdo to change dog to cat, throw an error in the first n entries
command! -nargs=1 TestCdo call Test(<q-args>)
function! Test(error_count)
let s:error_count = a:error_count
let s:error_index = 0
" restore a b
cdo e!
cdo call s:test_impl()
endfunction
function! s:test_impl()
if s:error_index < s:error_count
let s:error_index += 1
throw 1
endif
norm! c3lcat
endfunction
Test result:
Test dogs cats
---------------------------
TestCdo 1 dog0 cat1-7
TestCdo 2 dog0-1 cat2-7
TestCdo 3 dog0-2 cat3-7
TestCdo 4 dog0-7
TestCdo 5 dog0-7
TestCdo 6 dog0-7
TestCdo 7 dog0-7
TestCdo 8 dog0-7
It looks like cdo stops only if dog3 throws an error, dog3 is the last entry in a, does that mean That's very disturbing, especially if you have hundreds of files to deal with. Is this a bug?cdo only stops if last entry in a buffer cause an error?
I know you can create macro such as qp@q:cnext<cr>q to make it stop at first error, this question is not about that.
I'm using vim8.1-2127 on ubuntu16.04.
Update0
@Ralf's comment shows that cdo may continue to next buffer if all entries in a buffer throws an error.
Update1
@D.Ben.Knoble filed a bug report.
:cdo echo xand Vim printedE121: Undefined variable: xfor every entry in the qf list. I expected it to stop after the first error. Either I'm totally misinterpreting the docs or it is a bug. – Ralf Oct 21 '19 at 05:25:cdo echo x, I thout it would stop after the first 4 errors, but it didn't, which makes it even more mysterious. – dedowsdi Oct 21 '19 at 05:46cdostops if an error is detected, my goal is to prove it doesn't, the bold conclusion is in fact a question, there is a?after it, as i don't have solid prove, it's just an observation, Ralf's comment already shows that my conclusion is wrong. Sorry if my test examples give you confusion. – dedowsdi Oct 21 '19 at 12:38To your bold q:—I was attempting to answer your question, using an observation about your results. They give effective proof that the claim in the q is false. You might want to check:TestCdo 0, as I said, or try with only a single error (instead of many). Try with:debug. Then file a bug report. – D. Ben Knoble Oct 21 '19 at 13:12bis not changed, it doesn't conflict with my observation. I just tried to throw 1 instead of n, the result didn't conflict with my observation too, only throw indog3can stopcdofrom continue tob, only throw indog3can savedog4-7from being changed tocat4-7– dedowsdi Oct 21 '19 at 13:34global-like behavior – D. Ben Knoble Oct 23 '19 at 13:58