Как мне эмулировать нажатие клавиш внутри функции Vim? - PullRequest
21 голосов
/ 25 февраля 2012

Начну с кода

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

Я хочу создать функцию для быстрой прокрутки вверх и вниз с анимацией, чтобы я мог отслеживать, куда я иду.

Ответы [ 2 ]

37 голосов
/ 25 февраля 2012

Вы можете использовать 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>")
4 голосов
/ 25 февраля 2012

Попробуйте:

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

Буквально введите ctrl + v, а затем ctrl + y, что приведет к тому, что в вашем скрипте будет отображаться символ ^ Y

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...