0

Well I know it doesn't work because of the <Esc>, but is there any way to do it so that .(vim single redo) repeats the whole mapping and not only the part after the first <Esc> (without macros)?

I also tried replacing the <Esc> with ^o (CTRL_o) but it didn't work either. Any ideas?


I have this inside my init.vim:

nnoremap <leader>list 0i- `<Esc>$a`<Esc>

Explanation:

  • Jumps to start of the line
  • Insert - `
  • Jump to end of the line
  • Insert another `


Thanks for your help :)

1 Answer 1

1

That is not so simple, because pressing <Esc> typically ends an undo change.

There is :h i_CTRL-G_U, but this only works with the cursor keys, it doesn't help with using e.g. the <end> key.

However, if you change your mapping to perform the following:

Jump to the start of the line, change the rest of the line, insert your list characters - `, get the rest of the line and add the back-quote character again `, it should be repeatable. Something like this:

nnoremap <leader>list 0C-`<C-R>-`

This should be completely repeatable, with the exception of the move cursor to the beginning of the line, because cursor movements are not repeatable using . command.

7
  • I gave you an upvote for the smart idea, but this isn't working at all^^ 1. as you said the 0 movement won't be used again, which is really important and 2. The Small Delete Register (-) will be used over and over again, so you wll end up with the same line everywhere. Still interesting approach :)
    – Bog
    Jun 20, 2023 at 8:28
  • 1) as said, 0 is not repeatable as . command and there is no way to make it configurable. 2). small delete register is repeatable starting from a later vim 9.x patch, so you may need to upgrade here (needs patch 8.2.2189) Jun 20, 2023 at 8:33
  • 1. As I said, you said it already xD I was just repeating it^^ 2. Currently using neovim 0.6.1, the latest version... So I guess it is not possible with neovim^^
    – Bog
    Jun 20, 2023 at 8:37
  • neovim 0.6.1 is quite old, are you sure there is no newer version? Jun 20, 2023 at 8:39
  • oh wow yeah whoopsie sorry you are right. I was installing it with apt... neovim 0.6.1 is older than a year. Thanks for the hint :)
    – Bog
    Jun 20, 2023 at 8:45

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.