0

I hate the effect of the cursor going backwards after exiting insert mode when I have entered this mode using the i key. Is there an option that disables this?

If there is no such option then I also have an idea how to program this in lua, unfortunately neovim doesn't seem to have the right tools for this or I can't find them.

If I wanted to program it I would do it like this: autocmd on InsertEnter. Then I would need a function that reads the last key pressed and saves it, but neovim doesn't seem to have such a function (correct me if I'm wrong). Then save a global variable with a flag (or maybe there is a better way).

The other solution is to use vim.keymap.set('n', 'i', function()), where this function will save a global variable with a flag. Unfortunately I don't know how to call rhs ie i from this function, so that i still enters insert mode, something like continue event in javascript after preventDefault

Then in both of the above cases, autocmd would be set for InsertLeave, which would check if the i key was used to enter insert mode and if so, the cursor would be moved one field to the right.

Does anyone know if this is possible in neovim?

I'm looking for pure lua solution or as close as possible.

johnnyq
  • 15
  • 4
  • Almost. It took me to this: https://vim.fandom.com/wiki/Prevent_escape_from_moving_the_cursor_one_character_to_the_left and the Programmatic Alternative shown there looks like what i'm looking for, but can anyone translate it to lua? – johnnyq May 07 '23 at 19:21
  • I don't use nvim anymore, but from `:h lua-guide`, you should be able to put it in a `vim.cmd([[]])` – Zac Anger May 07 '23 at 19:36
  • @ZacAnger But then it doesn't use native nvim lua autocmd and others, so it's not a satisfactory solution. – johnnyq May 11 '23 at 15:25

0 Answers0