Search code examples
macrosneovim

How to add delay to macros ofr Neovim?


I want to use macros that jumping across files with telescope, so, macros may look like that one:

ve gsUKTran^M

That

  • ve - select the whole word
  • gs - start telescope search grep string
  • UKTRan - name of translation file
  • ^M - jump to the file

so that macros allows me to jump to required file by the key over cursor

but that macros doesn't work, because I need to add delays as telescope is fast, but macros is faster, I need smth like small timeout after UKTran

If I know is that possible, I think, I can modify macros row and save to register.


Solution

  • I have not found how to make a timeout, but instead I have utilized vim marks for that. I have added big letter marks (mA, mB) in files I need to jump and instead of using telescope, created a macros with marks, the final result for my case

    mZve"ay'A/<Ctrl-R>ave"ryf"vi""ty'BGo<Enter>"rpo* <Esc>"tpo* <Esc>

    Explanation:

    • mZ - put a mark at current place, so I can jump here later
    • ve"ay - yank the word into register 'a' (assumption cursor on the start of the word)
    • 'A - jump to mark A, in my case it was a file with english translations
    • /<Ctrl-R>a - <Ctrl-R>a is a search for the text in register a, so I am jumping to the phrase with the key yanked earlier
    • ve"ry - yank current key register r
    • f"vi""ty - yank translation value to register t
    • 'B - jump to second file, where I need output translations
    • Go<Enter><Esc>"rpo* <Esc>"tpo* <Esc> - create output record from register r and t

    PS. I have used here <Ctrl-R>, <Enter>, <Esc>, which are special characters, you can't copy them into register and replay