chromium-vim icon indicating copy to clipboard operation
chromium-vim copied to clipboard

Add option to autocenter search match.

Open ewancoder opened this issue 10 years ago • 9 comments

When vimium centers search result automatically, cVim does not do so (you need to press zz each time). This is frustrating, given that I have WM manager (or is it just chromium...) which makes chromium hide search results below (or above) visible screen sometimes. If the page is wider than your chromium window, search result which is on right invisible side of window could not be seen until you press $ or l. So please, make some kind of option (or as default behaviour) to always be able to see search result.

P.S. Another minor feature request is about saving image / yanking url of the image. Could you add some kind of visual mode which will loop through images (somehow highlighting them) with options to save it on hard drive or just yank url.

ewancoder avatar Jan 15 '15 10:01 ewancoder

As a temporary workaround, you can add this to your config file to automatically center find results:

map ^n nextSearchResult
map ^N previousSearchResult
map n :execute ^nzz<CR>
map N :execute ^Nzz<CR>

1995eaton avatar Jan 15 '15 17:01 1995eaton

@1995eaton thanks! Didn't think about mapping n key :)

ewancoder avatar Jan 15 '15 18:01 ewancoder

Is there any help needed to implement a feature which does this by one command? Should be pretty easy :)

hpurmann avatar Feb 24 '15 10:02 hpurmann

@hpurmann I'd rather keep things more vim-like, and I don't think vim has a setting like this. I do plan on making this fix easier to apply (without adding random mappings like '^n') with noremap:

noremap n nzz
noremap N Nzz

I'm only keeping this issue open as a reminder to implement noremap. Thanks for the support, though!

1995eaton avatar Feb 24 '15 19:02 1995eaton

Ok nice! Np

hpurmann avatar Feb 24 '15 19:02 hpurmann

Btw, when searching with /"sometext"<CR> it does not center first match, you need to press n or N. How to enable centering of the first match?

ewancoder avatar Feb 24 '15 20:02 ewancoder

Are you sure you really want that? Think about it: As you don't have any delimiter – like pressing the return key – after you are done typing your search string, the view could jump all over the screen while you type characters.

hpurmann avatar Feb 24 '15 23:02 hpurmann

@hpurmann well, the thing is, I want the search to jump with CR key, my last message messed up when I tried to write <CR>

ewancoder avatar Feb 25 '15 03:02 ewancoder

I miss the autocenter (both horizontally and vertically) during an incremental search. Autocentering the first match, after finalizing the search by a CR, would be a helpful compromise. The native Ctrl-F search is superior in these things.

The solution given here to center the {next,previous}SearchResult lacks support for [count] repetitions like '23n' for doing 'next' 23 times. Here is my solution:

" Centered search results
centerSearch(direction, absolute) -> {{
  repeats = Mappings.lastCommand.repeats -1;
  if (Mappings.lastCommand.repeatStr === '') {
    Mappings.actions[direction](1);
  }
  else {
    if (absolute) {
      Scroll.scroll('top');
      Find.clear();
    }
    Mappings.actions[direction](1);
    if (repeats) {
      Mappings.actions[direction](repeats);
    }
  }
  Mappings.actions.centerMatchH();
}}
map n :call centerSearch('nextSearchResult')<CR>
map N :call centerSearch('previousSearchResult')<CR>
map [n :call centerSearch('nextSearchResult', true)<CR>
map [N :call centerSearch('previousSearchResult', true)<CR>

The [n and [N mappings count from the start/end of the page, instead of the current match (param absolute = true). This way, you could jump to the N'th match on the page rather fast. Like so, for example:

/pattern<CR>21[n

Centers on the 21st match of pattern.
Personally, I most often want to start matching from the top, so my 'n' and 'N' are absolute for a quick '1n' like so:

map n :call centerSearch('nextSearchResult', true)<CR>
map N :call centerSearch('previousSearchResult', true)<CR>
map ]n :call centerSearch('nextSearchResult')<CR>
map ]N :call centerSearch('previousSearchResult')<CR>

skaniol avatar Oct 20 '19 16:10 skaniol