junegunn / vim-peekaboo

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

can this be made to work for C-r in cmode? #23

Closed jmlucjav closed 9 years ago

jmlucjav commented 9 years ago

I guess there is some reason why it's not already mapped to cmode or you would have already done so. But just double checking.

I naively tried:

cnoremap call peekaboo#peek(1, 'ctrl-r', 0)

and the sidebar shows up, but not sure how to go on. Needless to say, my knowledge of viml is limited to let this and let that...

junegunn commented 9 years ago

Peekaboo needs full control over the command-line to start itself (:call peekaboo#peak(...)). So on <CTRL-R> it should,

  1. Remember what's currently on the command-line. Also remember the position of the cursor.
  2. Clear the command-line and use it to start the sidebar
  3. When sidebar is closed, rebuild the command-line and restore the position of the cursor, and let Vim inject the content of the selected register. It's quite complicated, but probably not impossible. Special care must be taken to make it compatible with g:peekaboo_delay. I'll look into in when I get some time.
gelguy commented 9 years ago

This can be done with gelguy/Cmd2.vim with the following mappings.

function! s:Peekaboo()
    call peekaboo#peek(1, 'ctrl-r',  0)
endfunction

let g:Cmd2_cmd_mappings = {
    \ 'Peekaboo': {'command': function('s:Peekaboo'), 'type': 'function'},
    \ }

cmap <C-R> <Plug>(Cmd2)Peekaboo
junegunn commented 9 years ago

Yeah, what @gelguy suggested could be a better way to handle this. I've tried implementing the aforementioned scheme, but realized that it has to rely on fragile hacks with extensive use of feedkeys(). I'll mark this issue as wontfix and close it. Thanks.

jmlucjav commented 9 years ago

@gelguy tested this and works like a charm. Thanks both. @junegunn maybe it's worth mentioning this on the readme so this great usage does not go unnoticed?

junegunn commented 9 years ago

@jmlucjav Okay, I'll update the FAQ section.