Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
How do I type something different at each cursor when using multi-cursor editing in VS Code?
For example, say I have this CSS:
.ocean {}
.land {}
.sky {}
I want to give each of them a background-color, so I use multi-cursors and type:
.ocean { background-color: }
.land { background-color: }
.sky { background-color: }
Now how do I type a different colour for each one? Say blue, green, lightblue.
I would love to have a keybinding to rotate through the cursors and type one colour at a time, then go right back to multi-cursor editing so I could add the trailing semicolon and more CSS declarations inside each block.
The best workaround I've found is to open a text file and type one item per line, then copy-paste it into the CSS. Thankfully multi-cursors handles this correctly.
blue
green
lightblue
Note: This is based on this Stack Overflow question, but more specific (not a sequence of numbers, and not about Sublime). I'll post my own answer here shortly.
2 answers
Use the extension Insert Sequences. You just run the command Insert Sequences (extension.insertseq), then type what you want in square brackets, separated by commas:
[blue, green, lightblue]
This extension can also do other things like insert ranges of numbers and letters, with optional formatting. The default is to insert numbers, one for each cursor.
Note: I also posted this solution on Stack Overflow.
0 comment threads
You click on the first place and type blue. Then you click on the second place and type green. Then you click on the third place and type lightblue.
Multi-cursors are useful when you are typing the same thing in several places. If you are not typing the same thing, you don't have to use them.

0 comment threads