nvim-surround icon indicating copy to clipboard operation
nvim-surround copied to clipboard

Dot repeat of insert with surrounds is missing brackets

Open drybalka opened this issue 2 years ago • 1 comments

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-surround to 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.

drybalka avatar Jan 29 '24 07:01 drybalka

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.

phgz avatar Feb 01 '24 18:02 phgz