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

[Feature Request] Add `F` surround for surrounding in lambda #238

Closed alexmozaidze closed 1 month ago

alexmozaidze commented 1 year ago

Checklist

Is your feature request related to a problem? Please describe.

I wanted to surround my code with an anonymous function (aka lambda), I tried to use sf, but it surrounds in function call. "No problem!", I thought to myself, "I will use the capital F to get the desired result!". But the desired result never came.

Describe the solution you'd like

It'd be very handy to just sF and surround something in a function definition, like this:

Before (* represents cursor):

vim.keymap.set("n", "<leader><leader>", *telescope.builtin.find_files)

After yst)F:

vim.keymap.set("n", "<leader><leader>", function() *telescope.builtin.find_files end)

In order to determine if it should be inlined or multiline, I thought of using l/L instead of F. l for inline lambda, and L for multiline lambda.

Additional context

I am not aware of how this could be achieved without the help of treesitter (besides manually defining it for every file type), but it'd actually be cool to have a treesitter-powered function wrap.

kylechui commented 1 year ago

Tree-sitter is useful for structurally matching text inside the buffer; it's for figuring out what to surround, not what to surround with. As far as I know, the only way to implement this is to manually add per-filetype surrounds. I'm not keen on integrating this into the base plugin, as I don't know how to "guarantee" that a filetype-specific setup function defined by nvim-surround would run before a user-defined filetype-specific setup function. If anybody has any ideas for how this could be made feasible, feel free to leave them here.

kylechui commented 1 month ago

Further consideration has me thinking that the core of nvim-surround should remain simple and not try to handle any filetype-specific options by default. If you would like an F surround, please define it yourself using buffer_setup.