2012-02-25 17 views
17

Voy a empezar con código¿Cómo emulo una pulsación de tecla dentro de una función de Vim?

function BigScrollUp() 
    let count = 20 
    while count > 0 
    "Press" CTRL-Y <-- how do I emulate this? 
    sleep 5m 
    count -= 1 
    endwhile 
endfunction 

Quiero crear una función para desplazarse rápidamente hacia arriba y abajo, con la animación de modo que pueda realizar un seguimiento de dónde voy.

+1

ver esto: http://stackoverflow.com/questions/6409509/scripting-number-increment-decrement-in-vim – user1227804

Respuesta

3

Prueba esto:

" Press CTRL-Y: 
normal <Ctrl+v><Ctrl+y> 

Literalmente pulsar Ctrl + v, seguido por Ctrl + Y lo que resultará en un solo carácter se muestra como^Y en el script.

+0

no creo Vale la pena publicar mi propia pregunta para esto, pero ¿cómo remapearía Mayús + g para que, una vez que termine mi función, mi cursor se coloque en la última línea de mi archivo? He estado intentando iteraciones de 'normal ' –

+0

Simplemente intente hacer: 'normal G' Observe que' g' no es lo mismo que 'G' en ** vim **. –

+0

¿Por qué se necesita ''? – yangmillstheory

31

Puede usar feedkeys(). Tipo :help feedkeys para leer más:

feedkeys({string} [, {mode}])    *feedkeys()* 
     Characters in {string} are queued for processing as if they 
     come from a mapping or were typed by the user. They are added 
     to the end of the typeahead buffer, thus if a mapping is still 
     being executed these characters come after them. 
     The function does not wait for processing of keys contained in 
     {string}. 
     To include special keys into {string}, use double-quotes 
     and "\..." notation |expr-quote|. For example, 
     feedkeys("\<CR>") simulates pressing of the <Enter> key. But 
     feedkeys('\<CR>') pushes 5 characters. 
     If {mode} is absent, keys are remapped. 
     {mode} is a String, which can contain these character flags: 
     'm' Remap keys. This is default. 
     'n' Do not remap keys. 
     't' Handle keys as if typed; otherwise they are handled as 
      if coming from a mapping. This matters for undo, 
      opening folds, etc. 
     Return value is always 0. 

call feedkeys("\<C-Y>") 
Cuestiones relacionadas