nvim-surround
nvim-surround copied to clipboard
Dot repeat of insert with surrounds is missing brackets
Checklist
- [X] Have you tried updating the plugin to the latest version?
- [X] Have you checked the Breaking Changes issue?
- [X] Have you read through
:h nvim-surroundto see if there might be any relevant information there?
Neovim Version
0.9.5
Plugin Version
Tagged (Stable)
Minimal Configuration
require("nvim-surround").setup()
Sample Buffer
Keystroke Sequence
iaaa <C-g>s{bbb<Esc>j.
Expected behavior
aaa { bbb }
aaa { bbb }
Actual behavior
aaa { bbb }
aaa bbb
Additional context
Somehow surround in insert mode is not saved for dot repeat.
It's because the inserted text comes from the last inserted text . register. The current implementation uses the API to insert the extra text, thus not saving it in the actual typed text. To do so, feedkeys could come to the rescue. Something like (omitting handling special cases details):
vim.api.nvim_feedkeys(delimiter1 .. delimiter2
.. string.rep(
vim.keycode("<C-g>") .. "U" .. vim.keycode("<left>"),
#delimiter2
), "n", false)
CTRL-G U don't start a new undo block with the next i_CTRL-G_U
left/right cursor movement, if the cursor
stays within the same line
The documentation further states:
This makes it possible to use the cursor keys in Insert mode, without starting
a new undo block and therefore using |.| (redo) will work as expected.