Py Block Wrap
Eclipse/PyDev-style Cmd+4 for Python in VS Code:
- Wrap selected lines with banner lines and prefix each with
#
- With no selection, wraps the current line
- Keeps surrounding code untouched (no sticky parentheses or extra blank lines)
Usage
- Open a Python file
- Select lines (or place the cursor on a single line)
- Press Cmd+4 (Mac) or remap to your favorite keybinding
Command
pyBlockWrap.wrap
— Wrap with Python Banner
🪄 Example
Before
from datetime import datetime,timedelta,date
import numpy as np
from glob import glob
After pressing Cmd+4
from datetime import datetime,timedelta,date
####################################################################################
# import numpy as np
####################################################################################
from glob import glob
Default Keybinding
macOS:
{ "command": "pyBlockWrap.wrap", "key": "cmd+4", "when": "editorTextFocus && editorLangId == 'python'" }
Windows/Linux (suggested alternative):
{ "command": "pyBlockWrap.wrap", "key": "ctrl+4", "when": "editorTextFocus && editorLangId == 'python'" }
Local Install from VSIX
Package
npx @vscode/vsce package
This creates a file like py-block-wrap-0.0.1.vsix.
Install
Verify
- Open a .py file in your normal VS Code
- Use Cmd + 4 or Command Palette → Wrap with Python Banner
Uninstall (optional)
Troubleshooting
- Cmd + 4 does nothing / opens editor #4
- Command doesn’t trigger in non-Python files
- By design, the default keybinding only applies when editorLangId == 'python'
- You can broaden or change the condition in package.json if desired
Icon & Attribution
Coding icons created by Edwinp99 from Flaticon