Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dot repeat of insert with surrounds is missing brackets #301

Open
3 tasks done
drybalka opened this issue Jan 29, 2024 · 1 comment
Open
3 tasks done

Dot repeat of insert with surrounds is missing brackets #301

drybalka opened this issue Jan 29, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@drybalka
Copy link

drybalka commented Jan 29, 2024

Checklist

  • Have you tried updating the plugin to the latest version?
  • Have you checked the Breaking Changes issue?
  • 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 drybalka added the bug Something isn't working label Jan 29, 2024
@phgz
Copy link
Contributor

phgz commented Feb 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants