Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement inccommand #7416

Merged
merged 21 commits into from
Feb 7, 2022
Merged

Implement inccommand #7416

merged 21 commits into from
Feb 7, 2022

Conversation

adrsm108
Copy link
Contributor

What this PR does / why we need it:
This PR introduces the option inccommand, which enables a live preview of :s commands as they are typed. It also makes some improvements to interactive substitution with the c flag.

The feature is configured by setting vim.inccommand to 'append' or 'replace' (or '' to disable).
When set to 'append', substitution previews are inserted after each highlighted match, a behavior found in some popular vim emulators like spacemacs.
When set to 'replace', the substitution previews replace each match, which is consistent with the default behavior of neovim.

The config keys vim.substitutionColor and vim.substitutionTextColor are provided to control the appearance of preview text.

Which issue(s) this PR fixes
#6656
Also addresses #6655

Special notes for your reviewer:
Probably the biggest change from the original neovim behavior is how multi-line substitutions are handled. Since decorations can't change the apparent number of lines in the editor, concealed multi-line matches still have line breaks that won't be present once the substitution is performed. Multi-line replacements also have to be displayed inline; I currently do this by replacing line breaks with the character (U+23CE, "RETURN SYMBOL"), but it might be more sensible to use standard escape sequences.

adrsm108 and others added 11 commits January 17, 2022 15:26
- Add new config key vim.inccommand which can take values "", "append", or "replace"
- Add config keys vim.substitutionColor and vim.substitutionTextColor
- Add new abstract method getDecorations to CommandLine class
- Move logic for computing search highlights from updateSearchHighlights method of modeHandler to getDecorations method of SearchCommandLine
- Add closed field to Pattern class to keep track of whether the pattern was input with a closing delimiter
- In substitute.ts, separate argument resolution from command execution, and add new method to compute substitution decorations.
When executing an :s command with the c flag:
- Highlight current match with searchMatch, other matches with searchMatchHighlight
- Simulate incremental replacements by concealing confirmed substitutions with decorations
Move decoration utilities to their own file
When executing an :s command with the c flag:
- Highlight current match with searchMatch, other matches with searchMatchHighlight
- Simulate incremental replacements by concealing confirmed substitutions with decorations
Move decoration utilities to their own file
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@adrsm108
Copy link
Contributor Author

I'm not super familiar with github actions, but is this check working as intended? The only changes were to the README, and things seem to be going wrong when it's reformatted.

Copy link
Member

@J-Fields J-Fields left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@J-Fields J-Fields merged commit cb3c273 into VSCodeVim:master Feb 7, 2022
@adrsm108
Copy link
Contributor Author

adrsm108 commented Feb 7, 2022

My pleasure!

@Swoorup
Copy link

Swoorup commented Feb 8, 2022

I have been using this plugin for quite sometime, and didn't realise this feature had landed until I saw the preview when using the replace command. Just came to say thank you. 🙏 😊 🤩

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.

3 participants