haya14busa / incsearch.vim

:flashlight: Improved incremental searching for Vim
https://medium.com/@haya14busa/incsearch-vim-is-dead-long-live-incsearch-2b7070d55250
MIT License
1.11k stars 23 forks source link

Can't paste?! #35

Closed AndrewRayCode closed 9 years ago

AndrewRayCode commented 10 years ago

When I hit command-v (mac + macvim) in search mode it puts "+gP. What on earth?!

haya14busa commented 10 years ago

Please execute :registers and look for the register which stored "+gP.

haya14busa commented 9 years ago

Please reopen with more detail information.

harg commented 9 years ago

:registers command :

:registers
--- Registers ---
"*   haya14busaisthebest
":   registers

When I'm in the incsearch prompt and I want to paste with <D-v>, it insert "+gPinstead of haya14busaisthebest

haya14busa commented 9 years ago
IncSearchNoreMap <C-v> <C-r>+
IncSearchNoreMap <D-v> <C-r>+

How about <C-v> ? Doesn't it also work?

harg commented 9 years ago

With this mapping IncSearchNoreMap <C-v> <C-r>+ , <C-v> is working as expected and paste haya14busaisthebest

haya14busa commented 9 years ago

Thanks! Please give me the output of :echo "\<D-v>"

I guess it fails "" mapping handling, so could you trying another mappings like :IncSearchNoreMap <D-b> <Left>? If it didn't work, the problem would become more clearer.

harg commented 9 years ago

:echo "\<D-v>" => <80><fc><80>v

IncSearchNoreMap <D-b> <Left> => not working IncSearchNoreMap <C-b> <Left> => working

haya14busa commented 9 years ago

Hmm.. ok, please tell me your vim version, and :echo exists("+regexpengine")

harg commented 9 years ago

Macvim installed with homebrew : brew install macvim --HEAD --with-lua --override-system-vim

:echo exists("+regexpengine") => 1

:version

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Dec 12 2014 16:08:35)
MacOS X (unix) version
Included patches: 1-383
Compiled by Homebrew
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl             +cmdline_compl   +diff            +find_in_path    +jumplist        +mksession       +mouse_urxvt     +postscript      +signs           +tcl             +visual          +xim
+arabic          +cmdline_hist    +digraphs        +float           +keymap          +modify_fname    +mouse_xterm     +printer         +smartindent     +terminfo        +visualextra     -xsmp
+autocmd         +cmdline_info    +dnd             +folding         +langmap         +mouse           +multi_byte      +profile         -sniff           +termresponse    +viminfo         -xterm_clipboard
+balloon_eval    +comments        -ebcdic          -footer          +libcall         +mouseshape      +multi_lang      +python          +startuptime     +textobjects     +vreplace        -xterm_save
+browse          +conceal         +emacs_tags      +fork()          +linebreak       +mouse_dec       -mzscheme        -python3         +statusline      +title           +wildignore      -xpm
++builtin_terms  +cryptv          +eval            +fullscreen      +lispindent      -mouse_gpm       +netbeans_intg   +quickfix        -sun_workshop    +toolbar         +wildmenu
+byte_offset     +cscope          +ex_extra        -gettext         +listcmds        -mouse_jsbterm   +odbeditor       +reltime         +syntax          +transparency    +windows
+cindent         +cursorbind      +extra_search    -hangul_input    +localmap        +mouse_netterm   +path_extra      +rightleft       +tag_binary      +user_commands   +writebackup
+clientserver    +cursorshape     +farsi           +iconv           +lua             +mouse_sgr       +perl            +ruby            +tag_old_static  +vertsplit       -X11
+clipboard       +dialog_con_gui  +file_in_path    +insert_expand   +menu            -mouse_sysmouse  +persistent_undo +scrollbind      -tag_any_white   +virtualedit     -xfontset
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe  -DMACOS_X_UNIX  -I/usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/include/p
ython2.7 -I/usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/include/python2.7 -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -DNDE
BUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1     -I/System/Library/Frameworks/Tcl.framework/Headers  -D_REENTRANT=1  -D_THREAD_SAFE=1  -D_DARWIN_C_SOURCE=1
Linking: clang   -L. -L/usr/local/lib -L. -L/usr/local/lib -L/usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config -framework CoreFoundation -lpython2.7 -L/usr/lo
cal/lib -o Vim -framework Cocoa -framework Carbon       -lm  -lncurses -liconv -framework Cocoa  -L/usr/local/lib -llua -fstack-protector -L/usr/local/lib  -L/System/Library/Perl/5.16/darwin-thread-multi
-2level/CORE -lperl -framework Python  -F/System/Library/Frameworks -framework Tcl -framework CoreFoundation -framework Ruby
haya14busa commented 9 years ago

Hmm, it's weird... If exists("+regexpengine") is true, it should work from a quick reading in source code.

haya14busa commented 9 years ago
function! s:_split_keystring(str, ...)
    return split(a:str, '\%#=2' . "\\m\\%(" . get(a:, 1, '') . "\x80\xfc.\\%(\x80..\\|.\\)\\zs\\|\x80..\\zs\\|.\\zs\\)")
endfunction

function! s:split_by_keys(str)
    return s:_split_keystring(a:str, "\\%(\<Plug>\\|<Over>\\)(.\\{-})\\zs\\|")
endfunction

echo s:split_by_keys("\<D-v>")

Could you tell me the result of echo s:split_by_keys("\<D-v>") ?

harg commented 9 years ago

echo s:split_by_keys("\<D-v>") => ['<80><fc><80>v']

haya14busa commented 9 years ago

Thanks. I wonder why it doesn't work as expected considering your output(they are all expected behavior so far )... Hmm... could you tell me the result of the script below?

let s:V = vital#of('incsearch')
let s:String  = s:V.import("Over.String")
function! s:_as_key_config(config)
    let base = {
\       "noremap" : 0,
\       "lock"    : 0,
\   }
    return type(a:config) == type({}) ? extend(base, a:config)
\        : extend(base, {
\           "key" : a:config,
\        })
endfunction

function! s:_unmap(mapping, key)
    let keys = s:String.split_by_keys(a:key)
    if len(keys) > 1
        return join(map(keys, 's:_unmap(a:mapping, v:val)'), '')
    endif
    if !has_key(a:mapping, a:key)
        return a:key
    endif
    let rhs  = s:_as_key_config(a:mapping[a:key])
    let next = s:_as_key_config(get(a:mapping, rhs.key, {}))
    if rhs.noremap && next.lock == 0
        return rhs.key
    endif
    return s:_unmap(a:mapping, rhs.key)
endfunction

let s:dict = {
\   "\<C-v>": {
\       'key': "\<C-r>+",
\       'noremap': 1,
\   },
\   "\<D-v>": {
\       'key': "\<C-r>+",
\       'noremap': 1,
\   }
\ }

echo s:_unmap(s:dict, "\<C-v>") | " => ?
echo s:_unmap(s:dict, "\<D-v>") | " => ?

" Expect: => ^R+
harg commented 9 years ago
^R+
^R+
haya14busa commented 9 years ago

Agh...! Then, why \<D-v> doen't work expected..!?!?!? Hmm...

harg commented 9 years ago

:(

haya14busa commented 9 years ago

Considering the output("+gP), the first two characters("+) shows that it seems the mapping feature works as expected. However, the last two characters(gP) doesn't make sense...

Oh, I found there is :h gP in the vim help, and I guess it's related with this issue. <D-v> should be remapped, but it will be remapped by Vim(?) before inputing into the command-line of incsearch.vim

This really is workaround but could you try this mappings and type <D-v>? (without/with :IncSearchNoreMap <D-v> <C-r>+) (Please update incsearch.vim before trying because I forgot to fix an escape related bug.

IncSearchNoreMap "+gP <C-r>+
harg commented 9 years ago

Yes it's working. nice workaround, map the map :p

I see that the paste menu also execute execute "+gP

haya14busa commented 9 years ago

Out of curiosity, could you execute this command( :echo nr2char(getchar())) and type <D-v>?

harg commented 9 years ago

OK, if i re-assign the paste menu keyboard shortcut in OSX preference, the mapping IncSearchNoreMap <D-v> <C-r>+ now works...

So i guess <D-v> maps to "paste menu" (OSX system keyboard shortcut) and "paste menu" maps to "+gP

harg commented 9 years ago

:echo nr2char(getchar())) and type <D-v>=> "

haya14busa commented 9 years ago

Thank you for the investigation @harg :) I guess we finally found the real problem behind the scene...!

This is also out of curiosity, does "paste menu" work in the default command line?

harg commented 9 years ago

yep, "paste menu" works fine in the command line.

harg commented 9 years ago

is it helping? :

:menu

...
  40 &Paste
      n*   "+gP
      v&   "-c<Esc>:call paste#Paste()<CR>
      s&   "-c<Esc>:call paste#Paste()<CR> 
...
haya14busa commented 9 years ago

Thanks! I didn't know there are paste#Paste() function. However, there are no handling for c map (maybe vim deals it as n?). Hmm...

jordwalke commented 9 years ago

So it sounds like you found the solution. Will there be a fix?

haya14busa commented 9 years ago

@jordwalke

No, I didn't find good solution.

So i guess maps to "paste menu" (OSX system keyboard shortcut) and "paste menu" maps to "+gP

Since the system maps <D-v> to "paste menu" and it maps to "+gP, we cannot handle this from Vim script, I guess.

There are two solution.

1. workaround fix with IncSearchNoreMap

IncSearchNoreMap "+gP <C-r>+

https://github.com/haya14busa/incsearch.vim/issues/35#issuecomment-67504976

2. Remap system keymap

https://github.com/haya14busa/incsearch.vim/issues/35#issuecomment-67508752

jordwalke commented 9 years ago

My suggestion was that you automatically place IncSearchNoreMap "+gP <C-r>+ as a mapping if the user is running MacVim.

haya14busa commented 9 years ago

Hmm... but there is a downside to map IncSearchNoreMap "+gP <C-r>+. It cause waiting time for key a key code with typing ".

jordwalke commented 9 years ago

How much of a waiting time. I wasn't able to notice any additional time, though I'm usually very perceptive of additional interaction delays.

jordwalke commented 9 years ago

Oh, I just noticed that the delay is only in search mode. Yes, I definitely notice that. Is there a way control that delay amount only while in incsearch /?

haya14busa commented 9 years ago

I'm really sorry to late to reply. The delay amount is same as :h 'timeoutlen'.

You can control it only while in incsearch with autocmd.

augroup incsearch-timeoutlen
  autocmd User IncSearchEnter :let g:save_timeoutlen = &timeoutlen | set timeoutlen=0
  autocmd User IncSearchLeave :let &timeoutlen = g:save_timeoutlen
augroup END
jordwalke commented 9 years ago

Okay, maybe that's good enough for an official solution in the repo? You could even guard it under an "if macvim" check.

haya14busa commented 9 years ago

I added the workaround mapping in dev branch. https://github.com/haya14busa/incsearch.vim/compare/dev

Could you please trying the dev branch? I cannot confirm the fix because I don't have mac.

For the timeoutlen issue, I don't want to manipulate it by default since it affects other key mappings too.

haya14busa commented 9 years ago

I guess it's closable. Please reopen if not.