Repository navigation
2. Tutorial: Multiple Cursors
One of the most powerful features Helix has is multiple cursor.
Multiple cursors allow you to perform complex refactors which can be broken down to a series of steps, as well as search-and-replace.
The best way to learn is with examples, and we'll provide you with many examples on this page.
Note: Start of a selection is denoted by [[, end of a selection is denoted by ]].
We have some HTML which has repeating classes:
And we want to change each px-3 class to px-4, as well as each font-bold class to font-thin:
- First, begin by placing your cursor on the first
3: - Press Shift + c which creates a cursor below, until you have a cursor on each individual
3: - Press
rwhich will replace the character, and then4to replace each of the3s with a4. - Our goal is to change the class
font-boldtofont-thin, which you can do by pressing bbb until eachboldis highlighted: - Press c to change, and then type
thinand Esc to return back to normal mode.
There are often many ways to accomplish the same refactoring with different keystrokes in Helix, which provides nice flexibility.
Let's see the same example we have done previously, but in a slightly different manner.
- From the following state:
- Press gw to show two letters at the start of each word. Navigate to the first instance of the
boldword by pressing the 2-character key combination that you see: - The entire
boldword is highlighted now. Press Shift + C again 3 times until you select each instance ofbold: - As you see, the visual selection gets transferred over!
Change the contents of each selection by using c to delete and enter insert mode -- then type
thinand Esc to return back to normal mode. - Press f + 3 to extend the selection to the next
3for each selection: - We could delete the entire
px-3class if we wanted. Instead press a to append at the end of each selection, which puts us into insert mode. Delete the 3 by pressing backspace, then add a 4, exiting back to insert mode with Esc:
As you become more familiar, you'll learn to pick out more efficient ways of accomplishing the same task, and which method is better based upon circumstances.