Skip to content

feat!: Make setup optional.#296

Merged
kylechui merged 11 commits into
mainfrom
v3
Feb 22, 2026
Merged

feat!: Make setup optional.#296
kylechui merged 11 commits into
mainfrom
v3

Conversation

@kylechui

@kylechui kylechui commented Jan 15, 2024

Copy link
Copy Markdown
Owner

BREAKING CHANGE

EDIT: We will still use setup(...) and buffer_setup for configuration, but initialization is now done out-of-the-box. As in, setup is no longer mandatory for the plugin to function.

This commit will deprecate the existing setup and buffer_setup function calls, in line with this blog post. I believe that plugins, by default, should merely expose functionality but not actively modify user configuration at all. The goal is to have the installation script in the README contain the current "default" configuration, and any changes can be made by users directly. While this results in more code for the end user, I think that the reduced complexity and layers of abstraction will ultimately help users better understand the plugin and have more control for how it behaves.

The changes will be:

  • setup(...)vim.g.nvim_surround
  • buffer_setup(...)vim.b.nvim_surround

@bew

bew commented Sep 27, 2024

Copy link
Copy Markdown
Contributor

👍
Does that mean that we could theoretically dynamically add/remove surrounds that will then be available when triggering surround actions?

@kylechui

kylechui commented Feb 22, 2026

Copy link
Copy Markdown
Owner Author

👍 Does that mean that we could theoretically dynamically add/remove surrounds that will then be available when triggering surround actions?

I think I am currently leaning towards having a configure function that effectively "normalizes" the config DSL into something that's easier for the plugin engine to handle, but yes that should be possible.

Also sorry for the extremely late reply, I kinda lost motivation to work on this for a while, but recently have gotten interested in Vim plugin API design again. I think my goal is to have the plugin behave a bit more like a "traditional" Vim plugin---if you like the defaults then you shouldn't need to invoke/setup anything (similar to vim-surround), and instead of having some weird keymaps field I'll aim to provide a <Plug> API that you can bind yourself using vim.keymap.set.

@kylechui

Copy link
Copy Markdown
Owner Author

I also realize that I'm not great at writing documentation (although I'm trying to improve!), so any advice on how to improve the help docs would be much appreciated

Comment thread plugin/nvim-surround.lua Outdated
@kylechui kylechui marked this pull request as ready for review February 22, 2026 22:14
@kylechui kylechui changed the title feat!: Rewrite user configuration. feat!: Make setup optional. Feb 22, 2026
@kylechui kylechui merged commit 507db9a into main Feb 22, 2026
4 checks passed
@kylechui kylechui deleted the v3 branch February 22, 2026 22:37
kylechui added a commit that referenced this pull request Feb 22, 2026
In this feature/version upgrade, we make `setup` optional by decoupling
initialization and configuration of `nvim-surround`. We leverage
(Neo)Vim's built-in runtimepath lazy loading to initialize the plugin,
defining the public API in the form of `<Plug>` maps. Configuration is
still done via `setup`. Please see `:h nvim-surround.migrating.v3_to_v4`
for details on how to update your configurations.
kylechui added a commit that referenced this pull request Feb 22, 2026
In this feature/version upgrade, we make `setup` optional by decoupling
initialization and configuration of `nvim-surround`. We leverage
(Neo)Vim's built-in runtimepath lazy loading to initialize the plugin,
defining the public API in the form of `<Plug>` maps. Configuration is
still done via `setup`. Please see `:h nvim-surround.migrating.v3_to_v4`
for details on how to update your configurations.
@clason

clason commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Quick question: I've been using on-demand (not "lazy") loading via

M = { 'kylechui/nvim-surround' }

M.config = true

M.keys = {
  { 'ds' },
  { 'cs' },
  { 'ys' },
  { 'yS' },
  { 'S', mode = 'v' },
}

return M

which (still) works nicely, so I thought I could delete the config line -- but that errors with

E5108: Lua: ...are/nvim/lazy/nvim-surround/lua/nvim-surround/config.lua:333: attempt to index local 'aliases' (a nil value)
stack traceback:
        ...are/nvim/lazy/nvim-surround/lua/nvim-surround/config.lua:333: in function 'get_alias'
        ...hare/nvim/lazy/nvim-surround/lua/nvim-surround/utils.lua:45: in function 'get_nearest_selections'
        ...share/nvim/lazy/nvim-surround/lua/nvim-surround/init.lua:185: in function 'delete_surround'
        ...share/nvim/lazy/nvim-surround/lua/nvim-surround/init.lua:351: in function <...share/nvim/lazy/nvim-surround/lua/nvim-surround/init.lua:340>

Not a huge deal thinks still work as before; just wanted to mention it since I thought this would be a goal here.

@kylechui

Copy link
Copy Markdown
Owner Author

Hmm that is not intended behavior at all; I'll take a look at why that might be the case. Thanks for flagging

@kylechui

Copy link
Copy Markdown
Owner Author

@clason Do you mind testing out #423? I tried it myself and it appears to fix the issue that you were running into.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants