How do you move the cursor(s) to the next occurence of a character in Sublime Text?
Solution 1
In your particular use case, a good search to perform to isolate each value would be \w[^,\n]+
- make sure to click the regex button or hit Alt+R (Windows) / Cmd+Option+R (Mac) in the search field.
To navigate to the next match, use F3 (Windows) / Cmd+G (Mac). Shift+F3 / Cmd+Shift+G will navigate to the previous match. You can continue doing this after hitting Esc to dismiss the search field, and this will allow you to immediately edit the selected match.
Unfortunately, it doesn't appear that find-next can coexist with multiple selections - it ends up highlighting the first match in the last selection. You could highlight multiple lines, then split the selection into lines, then use Ctrl (Windows) / Cmd (Mac) + ← or → arrows to some degree, but that will obviously fall apart when some values have spaces.
Solution 2
One way to do this is to use vintage mode.
Edit your preferences (e.g. Settings - User
) to not ignore the vintage package (which it is in the default preferences).
{
"ignored_packages": []
}
When you have multiple cursors use the vim command f
followed by a character to move all the cursors to the next find of this character. (see https://stackoverflow.com/questions/12495442/what-do-the-f-and-t-commands-do-in-vim)
Unfortunately these only move to characters on the same line and cursors on lines without this character are left where they previously were located. The search command /
forgets your multiple cursors.
Solution 3
- CTRL+A => select all file
- CTRL+SHIFT+L => split selection into lines
- Home => move all selections to the start of the line
- ESC => enter command mode
- f, , => find and move cursors on each line to the first semicolon (repeat until you are on the one you are looking for)
- i => enter insert mode
Job done :)
twhb
Updated on September 18, 2022Comments
-
twhb over 1 year
Let's say we have a file containing this:
name, job, age Mark, Specialist, 24 Bob Guy, Manager, 43 Susan Third, Data Generation, 30
What I want to do is navigate around the fields. Move to the next field, select a field, etc. This is easily done in VIM by looking for commas (and assuming there are no escaped commas); is it also possible in Sublime Text? And in a way that works with multiple cursors, say one at the beginning of each line?
Bonus points if you can extend it to moving to the next substring or regex match.
-
Joost over 6 yearsDid you ever solve this?
-
twhb over 6 years@Joost No. As a workaround, I will sometimes isolate the text I'm working on (copy-paste into a new file), place cursors with a regex, insert unique markers like "XXX", do my editing, then remove the markers and copy-paste back into the original file.
-
-
twhb over 9 yearsThanks, this is a good hit at the problem, but I'm still hoping to find a way to work better with multiple cursors. I'll vote this up once I have the reputation for it.
-
Joost over 6 yearsWhat is this command mode you speak of?
-
Ronan Lamour over 6 yearsIn Sublime Text, if you hit ESC key, you enter in a "command mode". Then, you can hit a key like "f" to start a search. "vi" work in a similar way.
-
Admin almost 2 years@RonanLamour Sublime Text doesn't support this by default. A plugin with vi controls is needed for vi controls in Sublime Text.