3

Please consider these 3 small functions:

" place sign >> at line 10
function PlaceSign()
  call sign_define('a', {'text': '>>', 'texthl': 'LineNr'})
  call sign_place(10, 'g1', 'a', expand('%'), {'lnum' : 10})
endfunction

" echo the character typed by the user and clear sign
function EchoChar()
  let l:c = nr2char(getchar())
  echo l:c
  call sign_unplace('g1')
endfunction

" run both functions above one after the other
function PlaceEcho()
  call PlaceSign()
  call EchoChar()
endfunction

  • If I run :call PlaceSign() the result is as expected, it places sign '>>' at line 10
  • If I run :call EchoChar() it waits for the user input, then it echoes, and then clears sign

Now the problem:

  • If I run :call PlaceEcho() it waits for the user input, then it echoes, without running PlaceSign() first and I cannot understand why. The expected result would be: place sign at line 10, echo user typed character, clear sign. No idea why this is not happening.

1 Answer 1

4

Vim doesn't like updating Screen too often.

function PlaceEcho()
    call PlaceSign()
    redraw
    "^^^^^
    call EchoChar()
endfunction
1
  • Yup, that was it, thank you!
    – skamsie
    Dec 13, 2020 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.