Am 10.03.2010 18:23, schrieb Tim Chase:
Gary Johnson wrote:
I thought that a refinement of
:try | normal n | catch | n | endtry
with 'nowrapscan' set might work, but even that much didn't work for
me. I just got the error messages
Error detected while processing :
E385: search hit BOTTOM without match for: who
and the 'catch' clause was never executed.
Just cleaning up your example...I too got the uncatchable E385 whether
issued directly or <bar>'ed and issued as a mapping.
Again ...
:set nowrapscan
This works for me (typed at the cmdline):
:try| exec "normal! n"| catch| next| endtry
This does not work:
:nn n :try<bar>exec "normal! n"<bar> catch<bar> next<bar> endtry<CR>
But this works (surrounded with another :exec):
:nn n :exec "try<bar>exec 'normal! n'<bar> catch<bar> next<bar> endtry"<CR>
which I think is similar to:
However, if I wrapped it in a function, it seemed to work:
function! SearchWrap()
try
normal n
catch
n
endtry
endfunction
nnoremap <f4> :call SearchWrap()<cr>
seemed to do the trick for me with 'nowrapscan' set. I'm not sure why
the E385 refuses to be caught by an in-line (<bar>'ed) try/catch/endtry
block. I even tried wrapping the "n" in an exec, in case it was choking
on the bar as a parameter.
Andy's reply just came in:
@Gary: a try block cannot catch Beeps from a Normal mode
command.
It was an error message, not a Beep, ok.
but I'm not sure (1) where this is documented, and (2) why Gary and I
were getting the E385 (an error, not just a beep) and it still wasn't
being caught inline vs. in my function.
Seeing Andy's solution, I like it better, but I'm still left scratching
my head a bit on try/except issues.
-tim
I found this:
:h map_return
| Note that when an error is encountered (that causes an error message or beep)
| the rest of the mapping is not executed. This is Vi-compatible.
--
Andy
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php