Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to replace multi new line with single new line in Xcode using Find & Replace

In Xcode projects, we generally write programs without paying attention to line spacing.

So after coding is complete, how does one remove all those extra newlines with single line?

like image 220
Vijay-Apple-Dev.blogspot.com Avatar asked Apr 02 '11 09:04

Vijay-Apple-Dev.blogspot.com


People also ask

How do you find and replace in New Line?

On the keyboard, press Ctrl + H to open the Find and Replace dialog box, with the Replace tab active. On the Replace tab, click in the Find What box. On the keyboard, press Ctrl + J to enter the line break character.

How do I create a new line in Find and Replace in Visual Studio?

Today I learned How to find and replace with a newline in Visual Studio Code. In the local searchbox ( Ctrl + F ) you can insert newlines by pressing Ctrl + Enter . If you use the global search ( Ctrl + Shift + F ) you can insert newlines by pressing Shift + Enter .

How do I change multiple words in Xcode?

Control-Shift-Click. You can also hold Control-Shift while doing any of the things you would normally do to form a selection. For example: Double-click selects a word, so Control-Shift-Double-click selects a word and adds it to the existing selection.

How do you add a new line in Objective C?

In the C language we use '\n' for new line.


2 Answers

In the textual search field... one can do multiline / "non-printing character" search / replace by use of the following methods...

Say I wanted to replace all instances of

/**
 * This is a comment...

with

/**  This is a comment...

The "search term" would be entered as...

/**Alt/Option + EnterSpace*Space

and the replace term would be entered simply as...

/**Alt/Option + Tab

The moral of the story.. when you want to use characters that serve alternate purposes within the Search / Replace fields... combine the modifier Alt/Option with their entry to use them "literally".

like image 122
Alex Gray Avatar answered Nov 12 '22 01:11

Alex Gray


XCode's find and replace does not support multi-line regular expressions.

If you want to search for multiple lines you'll need to set your search option to "Textual" and either type option+return twice or copy/paste in two new lines chars. Then replace with a single new line char.

See here for more information.

like image 12
mmccomb Avatar answered Nov 12 '22 01:11

mmccomb