2012-02-25 7 views
17

Comincerò con il codiceCome si emula un tasto premuto all'interno di una funzione Vim?

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

Voglio creare una funzione per scorrere rapidamente su e giù, con l'animazione in modo che possa tenere traccia di dove sto andando.

+1

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

risposta

3

Prova questo:

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

digitare letteralmente Ctrl + v, seguito da CTRL + y che si tradurrà in un singolo carattere visualizzato^Y nello script.

+0

Non credo vale la pena di postare la mia domanda per questo, ma come rimappare Shift + g in modo che dopo la mia funzione termina il mio cursore è posizionato sull'ultima riga del mio file? Ho provato iterazioni di 'normale ' –

+0

Basta provare a fare: 'normale G' Si noti che' g' non è la stessa di 'G' in ** vim **. –

+0

Perché è necessario '? – yangmillstheory

31

È possibile utilizzare feedkeys(). Tipo :help feedkeys Per saperne di più:

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>") 
Problemi correlati