0

If we set a keymap that {lhs} is abc in normal mode. For example,

local opts = { noremap = true, silent = true }
vim.keymap.set('n', 'abc', function() print("Keymap abc!"), opts)

If we type abc in normal mode, where is the abc stored? Can we access it?

6
  • Could you tell us more about your goal? I suppose it will help us to help you? By definition of the mapping it is triggered when abc is typed. Commented Jun 14, 2023 at 11:11
  • 1
    Hi. Pardon me for the unclear description. In this question, I mean: in normal mode, neovim must "memorize/store" ab we just typed to be ready for triggering the map when we type c. I guess that there may be somewhere neovim "memorizes/stores" ab. Maybe ab is "memorized/stored" in some kind of "register" like mark register (e.g., ma marked in register a), yank register (e.g., "ay yanked in register a), or recording register (e.g., qa recorded in register a)? My goal is to access that "register", and I hope it can be used in the function part of vim.keymap.set().
    – HRC
    Commented Jun 14, 2023 at 11:56
  • Thanks it is clear. Is your goal is to use the same function for multiple mappings and to access the keybuffer to decide what to do in the function? Commented Jun 14, 2023 at 11:59
  • Yes! In the same vim.keymap.set() setting, I would like that the function take, e.g., (if we type abc) c in abc to do some process in the function, and (if we type abd) d to do the other process in the same function. Wait. So I have to set for abc and abd separately?
    – HRC
    Commented Jun 14, 2023 at 12:04
  • you can map ab and in your function call getchar() to get the next character and act upon this Commented Jun 14, 2023 at 12:52

0

Your Answer

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

Browse other questions tagged or ask your own question.