2012-02-25 7 views
17

私は私が私がつもり場所を追跡できるように、すぐにアニメーションで、上下にスクロールする機能を作成するコードVim関数のキー入力をエミュレートするにはどうすればよいですか?

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

から始めましょう。

+1

この参照:http://stackoverflow.com/questions/6409509/scripting-number-increment-decrement-in-vim – user1227804

答えて

3

これを試してみてください:

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

文字通り入力するスクリプトのように示される単一の文字^ YになりますCtrl + V、CTRL + Yが続きます。

+0

私は思いませんがこれは私自身の質問を投稿する価値はありますが、Shift + gを再マップすると、関数の終了後にカーソルがファイルの最後の行に配置されるようになりますか?私は 'normal ' –

+0

の反復を試しています。 'normal G' ** gim **の' G'と同じではありません。 –

+0

なぜ「」が必要ですか? – yangmillstheory

31

feedkeys()を使用できます。続きを読むには:help feedkeysを入力します。

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>") 
関連する問題