Testing in Python

Essential VS Code Keyboard Shortcuts for writing test data

Mitch Edmunds
2 min readApr 11, 2021

Writing out rows of test data can be tedious and boring, even if just a few lines. But mastering a few keyboard shortcuts in VS Code can make it fun. You’ll feel like a wizard and your friends will be impressed. So let’s get started…

Move Lines — [ALT + Up/Down Arrow]

Move any selection of lines up or down

Copy Lines — [SHIFT + ALT + Up/Down Arrow]

Quickly copy a line or a selection of lines with this shortcut

Select Every Occurrence — [CTRL + SHIFT + L]

Select every occurrence of a highlighted word

Replace all within selection — [CTRL + H -> Selection -> ALT + L]

This ones a little more involved: Select something to replace, press CTRL+H to bring up find and replace, TAB then type your replacement, then make a selection for which you want the find and replace to apply, press ALT+L to toggle replace within selection then CTRL+ALT+ENTER

Multiple Cursors 1 (mouse) — [ALT + Click]

Point and click to generate multiple cursors

Multiple Cursors 2 (keyboard) — [CTRL + ALT + Up/Down Arrow]

Use CTRL+U to undo a cursor extension and ESC to go back to a single cursor

Column Box Selection — [ALT + SHIFT + mouse drag]

You can also cut and paste selections if the number of cursors remains the same.

Hopefully you learned some new features of VS Code or have been convinced to give VS Code a try after witnessing the shortcuts above. If there are any shortcuts I’ve missed that you can’t live without when writing test data, please leave a comment!

--

--

Mitch Edmunds
Mitch Edmunds

Written by Mitch Edmunds

Building statistical pipelines for the ONS. Writing about testing and API design in pandas and PySpark. Enjoy cycling, learning Portuguese and playing piano!