0

I made the following keybinding to substitute "a/b" with "\frac{a}{b}".

-- convert / to \frac{}{}
-- (dot repeatable)
_G.div_to_latex = function()
  vim.cmd('execute "normal f/i\\<Del>}{\\<Esc>Bi\\\\frac{\\<Esc>Ea}\\<Esc>"')
  vim.go.operatorfunc = "v:lua.div_to_latex"
end
_G.div_to_latex_d = function()
  vim.go.operatorfunc = "v:lua.div_to_latex"
  return "g@l"
end
vim.keymap.set(
  "n",
  "èd",
  div_to_latex_d,
  {
    noremap = true,
    desc = "Convert / to \\frac",
    expr = true
  }
)

I would like the keybinding to be dot-repeatable, that is, to be able to be repeated by pressing ..

Unfortunately, only the last command (insert a }) gets repeated.

I though that resetting operatorfunc inside the function would be sufficient, but it isn't.

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.