Troydm
Troydm

Reputation: 2670

Vim visual key input strange behaviour

So i have following small test case

vnoremap <silent> d :<C-u>call Test()<cr>
vnoremap <silent> e :<C-u>call Test2()<cr>
fun! AskUser()
    let v = input('is this really ok with you? (y/n) ')
    redraw
    return v
endfun

fun! Test() range
    call AskUser()
    if 1
        echo 'hi hi hi'
        echo 'hi hi hi'
    endif
endfun

fun! Test2() range
    call AskUser()
    echo 'hi hi hi'
    echo 'hi hi hi'
endfun

So can anyone explain why visual mode d keybinding fails to show any message at all while e keybinding works without problem

Note the problem is not related to keybinding at all but to a fact that there is if statement after call to input function

I've tested it on MacVim and terminal vim on linux on latest vim versions compiled from mercurial source code and all have this problem

UPDATE: Some ppl didn't understood what the problem is. Well to be explained in details when you hit d in visual mode you get a input prompt and when you answer it you don't see any messages in command line while when you hit e and answer the prompt you see message hi hi hi twice in a row and 'Press ENTER or type command to continue' message

Upvotes: 1

Views: 276

Answers (1)

Birei
Birei

Reputation: 36252

I don't know the reason of that different behaviour but testing I realised that if the function ends with the conditional if and last sentence is the endif, then messages are not showed in screen.

I've created a custom vimrc only with your code and I have run it with vim -N -u new-custom-vimrc infile. Like that, I can reproduce the behaviour of the question, but it seems to work when I avoid the endif as last sentence of the function, like:

fun! Test() range
    call AskUser()
    if 1
        echo 'hi hi hi'
        echo 'hi hi hi'
    endif
    let dummy = 1 
endfun

Also works this:

fun! Test() range
    call AskUser()
    if 0
        return
    endif
    echo 'hi hi hi'
    echo 'hi hi hi'
endfun

Upvotes: 1

Related Questions