[document patch] :help g@ sample does not work properly when use blockwise-visual with '$'

36 views
Skip to first unread message

h_east

unread,
May 31, 2014, 3:32:18 PM5/31/14
to vim...@googlegroups.com
Hi Bram and Vim developers,

:help g@
doc> *g@* *E774* *E775*
doc> g@{motion} Call the function set by the 'operatorfunc' option.
(snip)
doc>
doc> Here is an example that counts the number of spaces with <F4>: >
doc>
doc> nmap <silent> <F4> :set opfunc=CountSpaces<CR>g@
doc> vmap <silent> <F4> :<C-U>call CountSpaces(visualmode(), 1)<CR>
doc>
doc> function! CountSpaces(type, ...)
doc> let sel_save = &selection
doc> let &selection = "inclusive"
doc> let reg_save = @@
doc>
doc> if a:0 " Invoked from Visual mode, use '< and '> marks.
doc> silent exe "normal! `<" . a:type . "`>y"
doc> elseif a:type == 'line'
doc> silent exe "normal! '[V']y"
doc> elseif a:type == 'block'
doc> silent exe "normal! `[\<C-V>`]y"
doc> else
doc> silent exe "normal! `[v`]y"
doc> endif
doc>
doc> echomsg strlen(substitute(@@, '[^ ]', '', 'g'))
doc>
doc> let &selection = sel_save
doc> let @@ = reg_save
doc> endfunction

This sample script does not work properly when use visual-block-mode with '$'.

How to reproduce:
(0) Prepare test.txt containing the following.
a a
b b b b
cc

(1) Copy to ~/.vimrc above sample script.
(2) Open test.txt
(3) Input below command.
<C-V>G$
(4) Press <F4>

Expected behavior:
- Display '5' on command line.

Actual behavior:
- Display '3'.


I think that we should use 'gv' in this case.
Attached a patch.

PS
Is it necessary condition "elseif a:type == 'block'" ?
Help says unnecessary. (Following excerpt)
doc> Although "block" would rarely appear, since it can
doc> only result from Visual mode where "g@" is not useful.

Thanks.

--
Best regards,
Hirohito Higashi

help_g_atmark.patch

Bram Moolenaar

unread,
May 31, 2014, 4:20:49 PM5/31/14
to h_east, vim...@googlegroups.com
Thanks!

> PS
> Is it necessary condition "elseif a:type == 'block'" ?
> Help says unnecessary. (Following excerpt)
> doc> Although "block" would rarely appear, since it can
> doc> only result from Visual mode where "g@" is not useful.

Right, it can be removed. I wonder if there is an example where "block"
would matter. Perhaps when changing text, e.g. adding a number to all
numbers in the selected area. That's much more complicated though.

--
Eagles may soar, but weasels don't get sucked into jet engines.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages