3

I have a CSV like this

id,name,city
1,John,New York
10,Peter,Los Angeles
223,Joseph,London

I'm in multiline select mode. I obtained the multiline cursor by selecting all the rows I needed and pressed ctrl+shift+L. I then pressed the home key, to go to the beginning of the line.

How would I select only the ids in this CSV (which of course is a lot larger than 3 lines)

I can for instance select a section like this, by holding the shift key and then the right arrow 3 times

1,J
10,
223

...but this is not what I want, rather I'd need this

1
10
223

Any way I can do this? I don't want to have to open vim unless it's absolutely necessary.

2 Answers 2

2

Here's what I would do:

CMD + A (select all)
CMD + SHIFT + L (multi line select mode)
CMD + LEFT ARROW (go to left of selection)
SHIFT + ALT + RIGHT ARROW (select first column)

With this input:

1,John,New York
10,Peter,Los Angeles
223,Joseph,London

It selects:

1
10
223

Note that I'm on Mac so I guess you have to use 'CTRL' instead of 'CMD'.

1
  • 1
    That does work, but has some limitations. For instance, if one of the IDs contains a dash while the others don't, then this doesn't work. Nov 28, 2016 at 13:19
1

I would suggest using the Find functionality instead of multiple cursors / multiline edit mode, although the following would also work with multiple cursors as long as the selection still covers the ids (i.e. so don't press Home).

  • Select the lines you are interested in, then open the Find panel (Find menu -> Find...).
  • Tick "In selection"
  • Ensure "Regular expression" mode is enabled
  • Enter ^[^,]* as the search string
  • Click the "Find All" button

This regular expression basically says: begin searching at the start of every line (in the selection) for any number of characters (including 0, in case some ids are missing, for example) that are not a comma.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.