Am 10.03.2010 17:01, schrieb Ben Fritz:
On Mar 10, 9:24 am, pixelterra<[email protected]>  wrote:
Like everyone, I use / and ? all day long, and use 'n' to go to the
next match. Often, instead of starting again at the top of the page, I
wish my 'n' (or some alternative) would go on to the next buffer/tab
instead of the top of the page.

Is there a setting or command for this? I've looked around and came up
empty.

No setting or option, but setting 'nowrapscan' will prevent you from
wrapping around to the top of the page, and then you can manually
switch to the next buffer, tab, or window, jump to the top with gg,
and continue on your way with n.

In a mapping:

    :nn <expr> n  &ws \|\| search("","nW")  ? "n" : ":bnext<CR>ggn"
    :nn <expr> N  &ws \|\| search("","bnW") ? "N" : ":bprev<CR>G$N"

Some notes:
- needs 'wrapscan' off (:set nowrapscan) to switch buffers;
  should be behave as usual with 'wrapscan'  on
- a count works ok
- bug: ignores that n can go backward, and N forward
- maybe :<C-U>bnext is better than :bnext
- maybe  :hide bnext  is preferred (if 'hidden' is not set); but maybe
  you will want to see the error message if the buffer has changes
- problem with folds:
search(@/) and n behave differently on closed folds; if the last two or
more matches are in a closed fold, then search(@/) will find the 2nd
match in that fold, but n will jump out of the fold.  Solution would be
to prepend the commands after the question mark with "zv" (open fold),
but then a count no longer works -> some more effort is needed.
- anyway: because we are in a mapping, n will no longer open folds
  (:h 'foldopen')
- I only assume that search("") is equivalent to search(@/),
  maybe even a little faster, as a compiled pattern will be reused?
  it's another assumption ...
- ... etc ...

@Gary: a try block cannot catch Beeps from a Normal mode command.

--
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

Reply via email to