junegunn / vim-peekaboo

:eyes: " / @ / CTRL-R
1.13k stars 39 forks source link

Open peekaboo window only after some timeout #5

Closed blueyed closed 9 years ago

blueyed commented 9 years ago

When you know exactly what register to use, peekaboo gets in the way (visually, but might also "eat" some keys).

It would be nice if it could be deferred, e.g. until CursorHold or something similar is triggered - given the limited async capabilities Vim has.

junegunn commented 9 years ago

visually, but might also "eat" some keys

Could you elaborate? I can understand that the flashing sidebar can be annoying sometimes, but peekaboo is not supposed to "eat" any keys.

blueyed commented 9 years ago

"eat" any keys

It's not peekaboo itself, but the interaction with Vim. It's not reproducible in a new Vim instance, but might be related to a more complex window / tab layout, where the flashing sidebar is slow to open, and then the register itself wasn't handled properly. It's good to know that this is not meant to happen - I will investigate in case it happens again.

blueyed commented 9 years ago

One annoyance in this regard is with the equalalways setting, which is on by default. This causes windows to be resized because of the opening/closing of the peekaboo window.

Maybe the equalalways setting could be disabled temporarily?

junegunn commented 9 years ago

I'm not sure if it's possible, according to :help equalalways

'equalalways' 'ea'  boolean (default on)
            global
            {not in Vi}
    When on, all the windows are automatically made the same size after
    splitting or closing a window.  *This also happens the moment the
    option is switched on.*

So even if I temporarily disable the option, windows will be resized right at the moment when I restore the option.

blueyed commented 9 years ago

This also happens the moment the option is switched on.

Ok, then it's not really an option. But maybe it can be taken into consideration for the timeout handling, e.g. with ea peekaboo would have the timeout by default or something like that.

junegunn commented 9 years ago

Yep, I see your point.

junegunn commented 9 years ago

Added g:peekaboo_delay (ms). Please test it and let me know if it doesn't work as expected. Thanks.

blueyed commented 9 years ago

Very nice! Thanks!

hallettj commented 5 years ago

I came found this discussion while searching for a way to close a window without losing sizes of other windows when equalalways is set. In my case I wanted to close a preview window. In case this is useful for peekaboo, or in case anyone else arrives here with the same problem, here is a solution that I am experimenting with:

function! s:isPreviewWindowOpen()
  for nr in range(1, winnr('$'))
    if getwinvar(nr, "&pvw") == 1
      return 1
    endif
  endfor
  return 0
endfunction

" Close preview window without changing the sizes of other windows.
function! s:closePreview()
  if !s:isPreviewWindowOpen()
    return
  endif

  let eq = &equalalways
  set noequalalways
  pclose
  if eq
    let cmd = winrestcmd()
    let &equalalways = eq
    exe cmd
  endif
endfunction

Turning equalalways back on at the end of the function resizes windows immediately, which we do not want. So I use winrestcmd to capture the size of each window before restoring the equalalways setting, and I run the restore command immediately after to get those sizes back.