Friday, July 11, 2014

Re: g@ seems to ignore user-defined motion maps

On Friday, July 11, 2014 12:51:47 PM UTC-5, ZyX wrote:
> > Having thought about it a bit, it occurs to me that it would be very difficult for Vim's g@ implementation to treat movements accomplished via user mappings the same as built-in {motion}s. Perhaps that's why only Vim {motion}s are considered? In the case of Paredit, Tamas has graciously agreed to add explicit normal mode mappings for d), c), etc..., which is an acceptable workaround.
>
> No, it is by no means different from motion support in `d` and other built-in operators. My translit3 plugin has no problems with using motion from camelcasemotion plugin and it uses `g@` under the hood. So you should search problem somewhere else.

This is not what I see. Here's a test case consisting of the map-operator example from the Vim help, along with a normal mode remapping of $ to G. Hitting $ in normal mode now goes to the end of the file, but hitting <F4>$ counts only the spaces on the current line...

Brett S.

nmap <silent> <F4> :set opfunc=CountSpaces<CR>g@
vmap <silent> <F4> :<C-U>call CountSpaces(visualmode(), 1)<CR>
nmap $ G

function! CountSpaces(type, ...)
let sel_save = &selection
let &selection = "inclusive"
let reg_save = @@

if a:0 " Invoked from Visual mode, use '< and '> marks.
silent exe "normal! `<" . a:type . "`>y"
elseif a:type == 'line'
silent exe "normal! '[V']y"
elseif a:type == 'block'
silent exe "normal! `[\<C-V>`]y"
else
silent exe "normal! `[v`]y"
endif

echomsg strlen(substitute(@@, '[^ ]', '', 'g'))

let &selection = sel_save
let @@ = reg_save
endfunction


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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment