2012-02-25 15 views
17

मैं कोडमैं विम फ़ंक्शन के अंदर एक कीप्रेस कैसे अनुकरण करूं?

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> 

सचमुच टाइप Ctrl + V, Ctrl + Y के बाद जो एक चरित्र के रूप में दिखाया^Y अपनी स्क्रिप्ट में कर दिया जाएगा।

+0

मुझे नहीं लगता कि इसके लिए मेरा खुद का प्रश्न पोस्ट करना उचित है, लेकिन मैं Shift + g को कैसे रीमेप करूँगा ताकि मेरे फ़ंक्शन समाप्त होने के बाद मेरे कर्सर को मेरी फ़ाइल में आखिरी पंक्ति में रखा जा सके? मैं 'सामान्य ' –

+0

के पुनरावृत्तियों की कोशिश कर रहा हूं बस कोशिश करें: 'सामान्य जी'ध्यान दें कि' जी' ** vim ** में 'जी' जैसा नहीं है। –

+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>") 
संबंधित मुद्दे