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.
skamsie
  • 235
  • 1
  • 6

1 Answers1

4

Vim doesn't like updating Screen too often.

function PlaceEcho()
    call PlaceSign()
    redraw
    "^^^^^
    call EchoChar()
endfunction
Matt
  • 20,685
  • 1
  • 11
  • 24