Wordwise Undo
Undo pasted or selected code one token at a time, starting from the end of a selected block.
Features
- Normal paste:
Ctrl + V continues to use VS Code's default paste.
- Arm Wordwise Undo:
Ctrl + Alt + P activates Wordwise Undo for the selected text.
- Undo one token:
Ctrl + Z removes the last token from the selected block.
- Outside text protection: text outside the selected block is not intentionally modified by token deletion.
- Automatic session cleanup: editing the document after activating a session ends the session to prevent stale text offsets from being used.
Keybindings
| Shortcut |
Action |
Ctrl + Alt + P / Cmd + Option + P |
Activate Wordwise Undo (whole file or selected block) |
Ctrl + Z / Cmd + Z |
Undo token from the end |
Ctrl + Y / Ctrl + Shift + Z (Mac: Cmd + Shift + Z) |
Redo last undone token |
Escape |
Stop / cancel Wordwise Undo session |
Usage
- Paste code normally using
Ctrl + V.
- Edit or format the pasted code as needed.
- Select the complete block you want to remove incrementally.
- Press
Ctrl + Alt + P to activate Wordwise Undo.
- Press
Ctrl + Z repeatedly to remove tokens from the end of the selected block.
Select the intended block carefully before activating the session.
Tokenization
Words, identifiers, numbers, and punctuation are treated as tokens. Whitespace is preserved while earlier tokens are removed. The final undo operation removes the remaining selected block, including its remaining whitespace.
Limitations
- This extension operates on a selected block; it does not automatically identify the original paste range.
- Changes made manually after activating a session cancel that session.
- The final token removal deletes the remaining block rather than restoring text that was previously overwritten.
- Rich-text clipboard formatting is not handled by this extension.
Development
Requirements: Node.js, npm, and Visual Studio Code.
Compile and check the extension:
npm install
npm run compile
Run the extension in a development host by opening this project in VS Code and pressing F5.
Packaging
Create a VSIX package:
npx @vscode/vsce package
Install the generated VSIX locally:
code --install-extension ./wordwise-undo-0.0.1.vsix
Replace the example filename above with the actual generated filename if the version changes.
License
Choose and add a license before publishing this extension publicly.