Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 1.29 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How do I emulate a keypress inside a Vim function?
  2. function BigScrollUp()
  3.   let count = 20
  4.   while count > 0
  5.     "Press" CTRL-Y <-- how do I emulate this?
  6.     sleep 5m
  7.     count -= 1
  8.   endwhile
  9. endfunction
  10.        
  11. " Press CTRL-Y:
  12. normal <Ctrl+v><Ctrl+y>
  13.        
  14. feedkeys({string} [, {mode}])               *feedkeys()*
  15.         Characters in {string} are queued for processing as if they
  16.         come from a mapping or were typed by the user.  They are added
  17.         to the end of the typeahead buffer, thus if a mapping is still
  18.         being executed these characters come after them.
  19.         The function does not wait for processing of keys contained in
  20.         {string}.
  21.         To include special keys into {string}, use double-quotes
  22.         and "..." notation |expr-quote|. For example,
  23.         feedkeys("<CR>") simulates pressing of the <Enter> key. But
  24.         feedkeys('<CR>') pushes 5 characters.
  25.         If {mode} is absent, keys are remapped.
  26.         {mode} is a String, which can contain these character flags:
  27.         'm' Remap keys. This is default.
  28.         'n' Do not remap keys.
  29.         't' Handle keys as if typed; otherwise they are handled as
  30.             if coming from a mapping.  This matters for undo,
  31.             opening folds, etc.
  32.         Return value is always 0.
  33.        
  34. call feedkeys("<C-Y>")