When I was editing a fairly large text, I accidentally hit
gq* instead of
gq} and then vim apparently seemed to freeze a moment with the message
search hit BOTTOM, continuing at TOP displayed in the command line. I found out it was because the
wrapscan option was enabled by default and when the word under cursor was not found between the cursor position and the end of the file, the search continued from the top.
But I should say this is not what we normally expect when formatting text. Besides, the
gq command behaves rather weirdly when search wraps round. So I'm trying to figure out how to set the
nowrapscan option when formatting text with
gq. Though I barely know anything about scripting, I managed to write the following function after reading a couple of topics in help:
nnoremap <F4> :set opfunc=GqNoWrapscan<CR>g@ function! GqNoWrapscan(type) let s:wrapscan = &wrapscan set nowrapscan silent exe "normal! '[gq']" let &wrapscan = s:wrapscan unlet! s:wrapscan endfunction
Unfortunately, this function does not work as expected. I still get the same message and the
nowrapscan option is apparently not set when I hit <F4>*. Could anyone help?