Sublime Forum

Split Into Lines

#1

Hello

I just purchased ST2 this evening because I had to do some major refactoring and the multiple selection & join lines & split into lines were just what I needed.

I searched this forum and found a few posts about how the OSX version of ST2 was not splitting a selection into lines. Then they posted that they had figured it out. The problem is that they did not write their solution!

How do you make a line with multiple words, separated by a space (or some other punctuation) move so that each word occupies one line?

When I press Command+Shift+L I see the menu flash, yet nothing happens. Then when I use the menu choice Split Into Lines, still nothing happens.

I saw one response to a post on this subject that you can merely select all of the spaces and press Return to get the same effect. If that is what we need to do, what is the menu choice and keyboard shortcut for?

I am certain I am doing something wrong, and the answer is right in front of my nose. I hope someone can give me some help.

0 Likes

#2

“cmd+shift+l” splits the selection into lines, though I don’t think that is what you want. Your selection would have to cover multiple lines before you hit the key command. Then, it would create a cursor at each line.

Anyways, take a look at my answer here. If you want to maintain the split character(s) you will have to modify the substitution some, but I think that should do what you want.

If you don’t want to use a plugin, you can always select the split character, then use cmd+d to select the necessary instances. You could also use the find all under command if you simply want to select all instances. Alternatively, you can use the find and replace functionality.

0 Likes

#3

I appreciate the response. I don’t mind using a plugin if that is what it takes.

I read on SO that you continued your “tech support” via chat. Is the code that shows on that SO page the final result?

The OP on that SO page wanted to do exactly what I am seeking to do, so I am thankful for the link you provided. :smile:

The question remains though, what does the menu choice “Split into Lines” do?

You wrote:

But that is exactly what I want. Perhaps we are referring to two separate things.

You wrote:

Does “Split Into Lines” refer to the cursor? If this is the case, I guess I assumed too much from watching the video on the ST2 homepage. I assumed since there was a Join Lines command, the Split Into Lines was the opposite of that. I just noticed that those two commands are located on two different menus: SIL is on Selection, and JL on Edit. :blush:

I will make use of your plugin. Thank you for the help.

brad

0 Likes

#4

Yes the SO page is the final result. The chat (and well most of the comments) were to help him get a plugin up and running. If you can do that though, the chat really isn’t useful :smile: . So split lines does the following…

It takes a region such as
http://i.imgur.com/tZZ49JO.png

and turns it into
http://i.imgur.com/7HQoGJt.png

It creates multiple cursors on the various lines, across your selections. So if you only highlight a single line, and run the split line command, it splits to 1 line, which is still 1 cursor :smiley: It’s not really the opposite of join lines. What it does is is quickly switching to multiple cursors after you make a selection.

I hope that makes things a little clearer.

0 Likes

#5

Choices, choices… Two easy ways that avoid writing plugins:

  1. Hilight your space, press Alt+F3 (windows) to select all, hit return.
  2. If the whitespace varies, use a regex search, then select all as above and hit return.

If you only want to do a subset of your file, you could use Ctrl+D to select them individually, or you could quickly CnP the desired section over to a new file before using the above method, then paste the fixed text back, or you could regex search within selection.

Pressing return will replace what’s hilited with a newline. If you don’t want to lose that whitespace char - eg, say its a comma you want to keep - just hit “right” before hitting return. The selections turn into cursors, and you newline at every cursorpoint.


2 Likes

#6

hah. nice post.

i saw that demo on the front page of the site and immediately wanted to try it as well.

in retrospect, it possibly might have made more sense to label that menu option (cmd+shift+l) “split cursor” instead of “split lines”. i think that more accurately describes what the text editor is doing in that case.

the ability to split a line selection using a quick search/regex would be really helpful for that very purpose. with all the support for python, it’d be interesting if one was able to hit a key-combo which brings up a text box to execute arbitrary code. something like:

selection.split(', ')

the cursor split and line join options are great though. although it took a few attempts to figure out how to split the lines in the first place (find/replace on just a single line). i half expected the command options to be consistent with other GUI editors (+F for find, +R for replace). instead, those commands seem to be a little jumbled around (possibly for familiarity with legacy text-based editors). additionally, some options in the same UI are alt+cmd+something vs. ctlr+alt+something (select regex expressions vs. replace all for exmaple). some consistency there, or context-sensitive options to reduce the number of key combinations required, might help simplify things.

all minor, and just a matter of not being familiar with the editor’s idioms yet i guess. i imagine those can be corrected with keybindings, but typically that won’t be reflected in the menu options (unless those are dynamic and not compiled in).

0 Likes

#7

I created an account solely to say THANK YOU! This saved me so much time. You’ve no idea!

0 Likes

#8

Appreciate the feedback. Though simple, this kind of thing is not always obvious to newcomers, as Sublime has different workflow options to your average editor. And some very neat tricks for stuff like this.

Glad to have helped! :slight_smile:

0 Likes