vim: Add gdefault setting to set /g as a default substitution flag#47664
Merged
dinocosta merged 3 commits intozed-industries:mainfrom Jan 27, 2026
Merged
vim: Add gdefault setting to set /g as a default substitution flag#47664dinocosta merged 3 commits intozed-industries:mainfrom
gdefault setting to set /g as a default substitution flag#47664dinocosta merged 3 commits intozed-industries:mainfrom
Conversation
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`.
- 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
dinocosta
approved these changes
Jan 27, 2026
Member
dinocosta
left a comment
There was a problem hiding this comment.
@bluetech Thank you for picking this one up and including tests! 🙌
I've pushed two smaller commits that add:
- Support for
:set [gd]defaultand:set [nogd]efaultin Zed's command palette - Documentation in
VimSettingsContentso that it shows while user's are editing the settings file - Update the test to use
NeoVimBackedTestContextso 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! 🙂
Contributor
Author
|
Thanks for improving the patch and merging! |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vim has a
:set gdefaultflag, which is described as follows:After using vim for years with this flag it is hard to remember to add
/gall the time, and I think this setting is convenient. So add support for this flag undervim.gdefault.The name
gdefaultcomes from vim, but if a less obscure name is better, I can change it tosubstitute_g_defaultorsubstitute_all_in_line_defaultor another suggestion.Was requested here: #36209
Also mentioned as a desired feature here (
gwas the default before this PR): #28138 (comment)Release Notes:
vim.gdefaultsetting to make/g(replace all matches in a line) the default for substitutions, along with:set gdefaultand:set nogdefaultcommands (short forms:gd,nogd)