77
votes

I am very new to Sublime Text and I am sure this is a naive question. Watching the Multiple line selection at http://www.sublimetext.com/ (2/6 slide). Absolutely love it.

I understand that Ctrl (Cmd)+Shift+L "multiple-selects" so that we could do the edit simultaneously. However, in the demo, they also merge all the lines into 1 single line. What is the shortcut for that?
I used Ctrl+J but it just deletes once and not all the occurrences of new line.

I use TextPad and use Find/Replace \n with an empty space. But it seems that the person giving the demo uses some kind of shortcut.

9

9 Answers

47
votes

I think that, in the demo, he presses Del, with the cursor at the end of the line, in multiple selection. This way the \n is removed in every selected line.

272
votes

A single command shortcut for merging multiple lines into 1 is "join lines".

  • Command + J on the Mac to join lines.
  • CTRL + J on Windows
  • Edit > Lines > Join Lines

Another approach is seen in the demo animations on sublimetext.com. Using multiple selections, Ctrl+Shift+L is used to split a selection into lines, and each line is then edited simultaneously. end + del will then remove all line breaks. This can be seen in slide 2/6 at http://sublimetexttips.com/7-handy-text-manipulation-tricks-sublime-text-2/

34
votes

ctrl+a and ctrl+j seems working on sublime text 3.

7
votes

Editing

join Joins the following line to the current line, replacing all in between whitespace with a single space

http://www.sublimetext.com/docs/commands

Go to edit option in menu, Edit -> line -> join lines

6
votes

Select the lines you want to merge and press Ctrl + j and if you want to make all file in 1 line then do Ctrl + a and Ctrl + j.

3
votes

If you want to merge lines into one line that will also remove the starting, and ending space from the line, the following regex should work:

Find What: ^\s*(.+)\s*\n
Replace With: \1
0
votes

Join lines is a good command, but it adds spaces between the merged lines. To merge lines without spacing, the easiest way appears to be the following:

  1. Find -> Replace (Command+Option+F on Mac)
  2. Ctrl+Enter to enter newline to the Find What field.
  3. Don't enter anything into the Replace With field.
  4. Press Replace All.
0
votes

I have been using a regex approach in Sublime Text 3, as follows:

  • Press Ctrl+H (in Windows) to show the "Find and Replace" dialog at the bottom.
  • In the "Find" field, use $\n\s* (end of line, carriage return and any arbitrary number of spaces following, including zero, which should be at the beginning of the next line).
  • The "Replace" field should be empty.
  • Hit "Replace All" or Alt+Ctrl+Enter.

This should do the trick!

0
votes

Sublime Text 3 for Mac:

cmd + j no longer works and is now CMD + SHIFT + J