On 03:21 Wed 30 Jan , Wiktor Ruben wrote:
> Hello,
>
> I have 'set wrapscan' in my .vimrc. During search Vim displays 'search
> hit bottom, continuing at top' message. It is pretty useless with
> 'wrapscan' because in most cases what I'm really interested in, is
> notification whether I have reached position from which my search
> started.
>
> Example: I have file with 1000 lines of text. I start '/foo' at line
> 400. I want to search whole file i.e. lines 400 - 1000 and 1 - 400.
> Then I want Vim to notify me "search hit starting position". Is there
> a way to make Vim to behave like this?
>
> Without such notification I end up racking my brain: "Hmm, have I
> already reached line 400?" every 'n' pressing after 'search hit
> bottom, continuing at top' message. I often miss starting position and
> after couple of redundant 'n' find myself doing search through text
> that has been already searched.
>
> My current workflow is to set 'nowrapscan', then mark my current
> position with 'mm', then 'gg' and doing 'n' until Vim displays 'search
> hit bottom, without match for foo'. Then I do '`m' to get back where I
> were before search. How can I improve it?
>
> --
> --
> 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
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
You can write your own function which can use searchpos() function,
setting mark with ':normal mmgg' (or even better remember the position in
a global (g:) variable. You can set the nowrapscan flag on the search()
function and only thet if the position is beyond (for forward search) if
it already hit bottom. Finally, you can write a command which invokes
the function. If you use <q-args> you will type a pattern in exactly
the same way as you type it in the command line. The last step would be
to makes maps n and N which invokes the search, but in such a way that
it uses the starting position set by the first search. I guess this
difficulty is the reason why vim behaves like it behaves. How you could
now using n/N that the search is a new search.
AFAIK vim has no option for that.
Happy Vimming,
Marin
--
--
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
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment