"." fails to repeat the last executed operator with ":normal v"

60 views
Skip to first unread message

Kana Natsuno

unread,
Nov 29, 2012, 9:35:08 AM11/29/12
to vim...@googlegroups.com
I often define my own text objects. But I noticed that some of them are
not correctly repeatable with the "." command. I investigated the cause
of the problem, and found a strange behavior about repeating an operator
which is executed with a ":" command as a motion.

If an operator is executed with a ":" command and the ":" command
doesn't invoke Visual mode via :normal, the whole operation can be
repeated correctly with the "." command. In this case, the ":" command
is stored into the redo buffer as is. For example:

------------------------------------------------------------------------

onoremap foo :<C-u>call Select()<CR>

function! Select()
" Select a region without ":normal v".
let p = getpos('.')
let p[2] += 3
call setpos('.', p)
endfunction

call setline('.', 'abc defg hijkl')
normal! 0
silent normal dfoo
echomsg string(getline('.'))
"==> ' defg hijkl'

delfunction Select
call setline('.', 'abc defg hijkl')
normal! 0w
let v:errmsg = ''
silent! normal! .
echomsg string(v:errmsg)
"==> 'E117: Unknown function: Select'
echomsg string(getline('.'))
"==> 'abc defg hijkl'

------------------------------------------------------------------------

But if an operator is executed with a ":" command and the ":" command
invokes Visual mode via :normal, the whole operation cannot be
repeated correctly with the "." command. In this case, the ":" command
is not stored into the redo buffer. For example:

------------------------------------------------------------------------

onoremap foo :<C-u>call Select()<CR>

function! Select()
" Select a region with ":normal v".
normal! viw
endfunction

call setline('.', 'abc defg hijkl')
normal! 0
silent normal dfoo
echomsg string(getline('.'))
"==> ' defg hijkl'

delfunction Select
call setline('.', 'abc defg hijkl')
normal! 0w
let v:errmsg = ''
silent! normal! .
echomsg string(v:errmsg)
"==> '', but it should be 'E117: Unknown function: Select'
echomsg string(getline('.'))
"==> 'abc g hijkl', but it should be 'abc defg hijkl'

------------------------------------------------------------------------

In the last example, the "." command repeats the last operation without
error, even if the Select function is no longer existing. So that the
redo buffer doesn't contains the last given ":" command as is.

The ":normal v" trick is necessary to define text objects like iw, ap
and others, because such text objects have to adjust the starting
position of a pending operator from Operator-pending mode.
But ":normal v" triggers the problem as described above.
Is this behavior intentional one, or unintended drawback?

Kana Natsuno

unread,
Mar 16, 2013, 1:37:18 AM3/16/13
to vim...@googlegroups.com
On Thursday, November 29, 2012 11:35:08 PM UTC+9, Kana Natsuno wrote:
> I often define my own text objects. But I noticed that some of them are
> not correctly repeatable with the "." command. I investigated the cause
> of the problem, and found a strange behavior about repeating an operator
> which is executed with a ":" command as a motion.
>
> If an operator is executed with a ":" command and the ":" command
> doesn't invoke Visual mode via :normal, the whole operation can be
> repeated correctly with the "." command. In this case, the ":" command
> is stored into the redo buffer as is. For example:
>
> [...]

Don't you have any idea about this problem?

Reply all
Reply to author
Forward
0 new messages