0

I have a very long list of words like this in the Atom editor

car
cat 
dog
town

I would like to convert this with Atom into an array like this:

['car', 'cat', 'dog', 'town']

It is easy to create a ' on the left of all words by putting the cursor left to car and then pressing alt+shitf+arrow_down till one reaches town and then pressing '. For the right, the best thing I found is to to click at the end of each word with the mouse and pressing control till all cursors are set. Then just add ', and backspace. This gives me

'car', 'cat', 'dog', 'town'

but its very cumbersome for a very long list. Is there a better method to this task in Atom?

Adam
  • 25,960
  • 22
  • 158
  • 247
  • 1
    I think it was already covered here https://stackoverflow.com/questions/25076300/convert-word-list-into-array – idontknowcoding Dec 23 '19 at 18:50
  • 1
    @idontknowcoding this question is asking if this task is possible to achieve in atom. The question that you refere to is asking for a script that does it. I should make it more clear that this is atom specific. I only had the tag. – Adam Dec 23 '19 at 18:55
  • 1
    Does atom support multi-cursors? In Sublime it would something like: Ctrl-A, Ctrl-Shift-J, Home, "'", End, "', ", Delete then fixup the start and end (finger memory isn't perfect :|) – user2864740 Dec 23 '19 at 18:57
  • @user2864740 yes atom does support multi-cursors. Ctrl+A will select everything and Shift+J just replaces everything with capital J ^^ – Adam Dec 23 '19 at 19:00
  • @Adam It would in Sublime too, needs the Ctrl. Now I'm curious, downloading Atom :D – user2864740 Dec 23 '19 at 19:02
  • @user2864740 hm, ctrl+shift+J does unfortunately do nothing in atom – Adam Dec 23 '19 at 19:03
  • @Adam Same sequence works in Atom - just have to use the menu to enter multi-cursor-mode (or setup a binding, perhaps..) – user2864740 Dec 23 '19 at 19:07

2 Answers2

2

Use the find & replace function with the regex option.

Replace new lines \n with ',', for example.

how to use the find&replace function with regex option

António
  • 103
  • 1
  • 7
1

In a just-downloaded Atom, I was able to use the following sequence.

The "Split Into Lines" does not appear to have a default keybinding, although once setup it would be possible to perform the (somewhat long) sequence of steps sans-Menu.

  • Ctrl+A - selects all
  • Menu -> Selection -> Split Into Lines
  • Home - moves all cursors to the start/end of each line and wrap
  • '
  • End
  • ',Space
  • Delete - collapses lines
  • Home - change back to single-cursor mode and select entire line
  • Shift-End
  • [ - this auto-bracketed the selected text "['car', ..., 'town', ]"
  • End - now tidy up the the ", " before the end "]"
  • Left-Arrow
  • Backspace
  • Backspace

Not quite as short as a regex-replace.. adapt and/or take concepts as useful. Multi-cursor mode is incredibly powerful in certain cases.

user2864740
  • 60,010
  • 15
  • 145
  • 220
  • What do you mean with `menu multi-select` ? I only have `File`, `Edit`, `View`, `Selection`, `Find` `Packages` and `Help` in my menu. – Adam Dec 23 '19 at 19:10
  • "Menu -> Selection -> Split Into Lines" - no extra packages. I just downloaded whatever was "Windows 64-bit installer". – user2864740 Dec 23 '19 at 19:11
  • Ah perfect, that was exaclty the kind of instructions that I wished for. Actually after clicking `split into lines` I can directly insert `'` which will put single quotes on both ends of every line. – Adam Dec 23 '19 at 19:21