6

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.

2
  • Did you ever solve this?
    – Joost
    Commented Nov 3, 2017 at 15:10
  • @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
    Commented Nov 4, 2017 at 8:29

3 Answers 3

5

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.

1
  • Thanks, 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.
    – twhb
    Commented Nov 21, 2014 at 16:13
4

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.

1
  • 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 :)

3
  • 1
    What is this command mode you speak of?
    – Joost
    Commented Nov 3, 2017 at 15:10
  • In 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. Commented Nov 10, 2017 at 15:38
  • @RonanLamour Sublime Text doesn't support this by default. A plugin with vi controls is needed for vi controls in Sublime Text.
    – matj1
    Commented May 19, 2022 at 14:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .