Skip to content

vim: Add gdefault setting to set /g as a default substitution flag#47664

Merged
dinocosta merged 3 commits intozed-industries:mainfrom
bluetech:gdefault
Jan 27, 2026
Merged

vim: Add gdefault setting to set /g as a default substitution flag#47664
dinocosta merged 3 commits intozed-industries:mainfrom
bluetech:gdefault

Conversation

@bluetech
Copy link
Contributor

@bluetech bluetech commented Jan 26, 2026

vim has a :set gdefault flag, which is described as follows:

'gdefault' 'gd'         boolean (default off)
                    global
    When on, the ":substitute" flag 'g' is default on.  This means that
    all matches in a line are substituted instead of one.  When a 'g' flag
    is given to a ":substitute" command, this will toggle the substitution
    of all or one match.  See complex-change.

            command         'gdefault' on   'gdefault' off
            :s///             subst. all      subst. one
            :s///g            subst. one      subst. all
            :s///gg           subst. all      subst. one

After using vim for years with this flag it is hard to remember to add /g all the time, and I think this setting is convenient. So add support for this flag under vim.gdefault.

The name gdefault comes from vim, but if a less obscure name is better, I can change it to substitute_g_default or substitute_all_in_line_default or another suggestion.

Was requested here: #36209
Also mentioned as a desired feature here (g was the default before this PR): #28138 (comment)

Release Notes:

  • vim: Add vim.gdefault setting to make /g (replace all matches in a line) the default for substitutions, along with :set gdefault and :set nogdefault commands (short forms: gd, nogd)

vim has a `:set gdefault` flag, which is described as follows:

    'gdefault' 'gd'         boolean (default off)
                        global
        When on, the ":substitute" flag 'g' is default on.  This means that
        all matches in a line are substituted instead of one.  When a 'g' flag
        is given to a ":substitute" command, this will toggle the substitution
        of all or one match.  See complex-change.

                command         'gdefault' on   'gdefault' off
                :s///             subst. all      subst. one
                :s///g            subst. one      subst. all
                :s///gg           subst. all      subst. one

After using vim for years with this flag it is hard to remember to add
`/g` all the time, and I think this setting is convenient. So add
support for this flag under `vim.gdefault`.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 26, 2026
- Update `vim::normal::search::Replacement.parse` to correctly handle
  the case where multiple `g` flags are provided, where each one should
  invert the effect of a previous one, similar to what Neovim does
- Update documentation in `settings_content.VimSettingsContent.gdefault`
  so it shows for users while editing the settings file
- Update the `test_replace_gdefault` test to use
  `NeovimBackedTestContext` instead of `VimTestContext` so we actually
  test against Neovim's behavior
Copy link
Member

@dinocosta dinocosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bluetech Thank you for picking this one up and including tests! 🙌

I've pushed two smaller commits that add:

  • Support for :set [gd]default and :set [nogd]efault in Zed's command palette
  • Documentation in VimSettingsContent so that it shows while user's are editing the settings file
  • Update the test to use NeoVimBackedTestContext so that we actually test against Neovim's behavior

Will just run this over someone else in the team to ensure that we're ok with using gdefault for the setting name, but it's looking good. Thank you so much! 🙂

@dinocosta dinocosta merged commit 41ce23f into zed-industries:main Jan 27, 2026
28 checks passed
@bluetech bluetech deleted the gdefault branch January 27, 2026 20:29
@bluetech
Copy link
Contributor Author

Thanks for improving the patch and merging!

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

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants