New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeat of a custom operator over a range of lines only works on command-line, garbles text when run inside a function #1619

Closed
inkarkat opened this Issue Apr 6, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@inkarkat
Copy link

inkarkat commented Apr 6, 2017

Scenario

A simple action (like gUi": upper-casing the next quoted string) can be repeated on multiple selected lines via :'<,'>normal! . I wanted to define a visual mode mapping for that, and as it grew additional logic (like handling characterwise vs. linewise differently), extracted the code into a :function. After that, custom operators stopped working: The repeat only works successfully on the first line; subsequent lines are garbled / just have some text removed instead of getting the operator applied.

Reproduce

Needs to be a custom operator; the actual action is not important.

nnoremap g. :set opfunc=Operator<CR>g@
function! Operator( type, ... )
    let @x = 'XXX'
    execute 'normal! g`[' . (a:type ==# 'line' ? 'V' : 'v') . 'g`]' . '"xp'
endfunction

Sample text.

new
insert
Pellentesque "gravida" egestas mi. Integer rutrum tincidunt libero.

Suspendisse quis mi eget "dolor sagittis" tristique. Aenean non pede eget nisl
bibendum gravida. Class "aptent taciti sociosqu" ad litora torquent per "conubia"
nostra, per inceptos himenaeos. "Morbi laoreet." Suspendisse "potenti".

Suspendisse quis mi eget "dolor sagittis" tristique. Aenean non pede eget nisl
bibendum gravida. Class "aptent taciti sociosqu" ad litora torquent per "conubia"
nostra, per inceptos himenaeos. "Morbi laoreet." Suspendisse "potenti".
.

Execute once to prime repeat.

1normal g.i"

The problem is only with custom operator; a built-in command (like gU) works fine: 1normal gUi"

When repeating directly in the command-line: works.

3,5normal! .

When repeating from within a function: broken!

function! Apply()
    7,9normal! .
endfunction
call Apply()

Result:

Pellentesque "XXX" egestas mi. Integer rutrum tincidunt libero.

Suspendisse quis mi eget "XXX" tristique. Aenean non pede eget nisl
bibendum gravida. Class "XXX" ad litora torquent per "conubia"
nostra, per inceptos himenaeos. "XXX" Suspendisse "potenti".

Suspendisse quis mi eget "XXX" tristique. Aenean non pede eget nisl
da. Class "aptent taciti sociosqu" ad litora torquent per "conubia"
ceptos himenaeos. "Morbi laoreet." Suspendisse "potenti".

Same steps are in the attached bug-range-repeat.zip; execute with

$ vim -N -u NONE -S bug-range-repeat.vim

I can reproduce this on latest Vim 8.0.543, Vim 7.4.1689 (both Linux/x64) as well as all Vim 7.{0,1,2,3,4} releases on Windows/x86.

@brammool brammool closed this in d4863aa Apr 7, 2017

desvp added a commit to desvp/vim that referenced this issue May 30, 2017

patch 8.0.0548: saving the redo buffer only works one time
Problem:    Saving the redo buffer only works one time, resulting in the "."
            command not working well for a function call inside another
            function call. (Ingo Karkat)
Solution:   Save the redo buffer at every user function call. (closes vim#1619)

ckelsel added a commit to ckelsel/neovim that referenced this issue Jun 23, 2018

vim-patch:8.0.0548: saving the redo buffer only works one time
Problem:    Saving the redo buffer only works one time, resulting in the "."
            command not working well for a function call inside another
            function call. (Ingo Karkat)
Solution:   Save the redo buffer at every user function call. (closes vim/vim#1619)
vim/vim@d4863aa

justinmk added a commit to neovim/neovim that referenced this issue Jun 24, 2018

vim-patch:8.0.0548: saving the redo buffer only works one time (#8629)
Problem:    Saving the redo buffer only works one time, resulting in the "."
            command not working well for a function call inside another
            function call. (Ingo Karkat)
Solution:   Save the redo buffer at every user function call. (closes vim/vim#1619)
vim/vim@d4863aa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment