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.
A single command shortcut for merging multiple lines into 1 is "join lines".
Command + Shift + J on the Mac to join lines.
CTRL + Shift + J on Windows
Edit > Lines > Join Lines
Important note: This keyboard shortcut changed in versions of sublime text released after around mid-2021. For older versions, use Command + J, or CTRL + J.
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/
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.
ctrl+a
and ctrl+j
seems working on sublime text 3.
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
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
.
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
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:
Find -> Replace (Command+Option+F on Mac) Ctrl+Enter to enter newline to the Find What field. Don't enter anything into the Replace With field. Press Replace All.
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!
Sublime Text 3 for Mac:
cmd + j no longer works and is now CMD + SHIFT + J
Success story sharing