kylechui / nvim-surround

Add/change/delete surrounding delimiter pairs with ease. Written with :heart: in Lua.
MIT License
2.92k stars 60 forks source link

Surround from the current cursor till the end of line #218

Closed kohane27 closed 4 months ago

kohane27 commented 1 year ago

Hello there. Hope you're doing well. Thank you for creating nvim-surround.

I migrated from vim-sandwich. There's a built-in feature as shown below:

https://user-images.githubusercontent.com/57322459/223746223-f183bc75-a5dc-4302-92a4-673af1dd34f7.mp4

Basically, pressing yS allows a user to surround from the current cursor till the end of line.

I've looked into the doc and nvim-surround doesn't seem to have this functionality. I wonder if you'll consider to implement it? Thank you!

kylechui commented 1 year ago

In my opinion, this isn't something that I would want to implement as part of the default mappings; hopefully this suffices for your use case:

vim.keymap.set("n", "yS", "<Plug>(nvim-surround-normal)$")
require("nvim-surround").setup({
    keymaps = {
        normal_line = false,
    }
})
kohane27 commented 1 year ago

Thank you @kylechui for your prompt reply and the solution. It works perfectly! Thank you again!

kohane27 commented 1 year ago

Apologies for bothering you again.

Is there any changes to the API?

Today I realized vim.keymap.set("n", "yS", "<Plug>(nvim-surround-normal)$") doesn't work anymore.

But I checked https://github.com/kylechui/nvim-surround/issues/77 and there doesn't seem to be any recent changes.

:verbose map yS
n  yS          * <Plug>(nvim-surround-normal)$
        Last set from Lua

Any input is much appreciated. Thank you!

kylechui commented 1 year ago

I don't believe so, can you try it with just nvim-surround installed? Please provide some minimal config

kohane27 commented 1 year ago

Hello @kylechui , thank you for getting back to me. I really appreciate it.

I've further tested and it turned out that the problem is triggering the command. Please see the video below:

https://github.com/kylechui/nvim-surround/assets/57322459/b813c653-9ba1-416e-af18-5f6d977582e6

I thought it's the problem with the trigger command, so I changed it to ys:

vim.keymap.set("n", "ys", "<Plug>(nvim-surround-normal)$")

https://github.com/kylechui/nvim-surround/assets/57322459/b166ff81-f31b-485c-aba7-e9a40420ae0e

My timeoutlen value is 450 and I tried changing it to 1000, but the same thing occur: I need to press ys quite quickly in order to trigger the command. I think this is not nvim-surround problem. Thank you for confirming with no API changes and I'll investigate further.

kylechui commented 1 year ago

Let me know if you discover the root cause!

kylechui commented 4 months ago

@kohane27 I just realized that this is probably due to after the timeout for ys expiring, Neovim is now awaiting some motion to be passed into the yank action. By default, s is not a well-defined motion, so ys slowly effectively just cancels the action.