Blazej SLEBODA
Blazej SLEBODA

Reputation: 9915

Multiline find & replace in Xcode

I would like to replace

import Quick
import Nimble

with

import XCTest

Is it possible to do it in Xcode find and replace or I have to use Xcode regular expressions?

I have tried: import Quick\nimport Nimble but it doesn't work as expected

Upvotes: 1

Views: 1050

Answers (3)

L33MUR
L33MUR

Reputation: 4058

THE FAST WAY:

You can simply copy both lines dragging with the mouse and the paste them on find textfield.

THE COOL LEEMUR'S WAY:

But also there is a great way to find expressions:

  • Press CMD + f

  • A find field will appear on the top of the editor.

  • At the right side of the find field there is a "+" sign enter image description here

  • Press "+" will display a list of special characters enter image description here

  • Its very useful, you can make something similar to regular expressions, mixing literal text with patterns enter image description here

  • You can try to find the expression just in the current file writing it in the top find field. Or you can try to find the expression in the whole project using the Find Navigation tab on the left. As you will see the expression will appear there also.

  • Moreover if you want you can use an actual regular expression to find something if you press in the word "Contains" at the left of the "+" sign. It will show a list where you can select the option "Regular Expression"

  • If you want to find text select "Find" at the left of the editor. If you want to replace it, select "Replace" and a new field will appear below.

  • You can replace the text with another pattern, using some of the words that you used to find the text. If you double clic on "Word1" at the find field it will appear at the replace field.

  • In this example I'm changing the order of two words around MyTextenter image description here

Upvotes: 2

wzso
wzso

Reputation: 3885

I don't know how you tried and failed. But I tried and it worked. Procedures as bellow:

  1. First select and copy the lines you wanna replace.
  2. Shift+Option+CMD+F to open Find navigator in Xcode, then CMD+V to paste the multiline text.
  3. You can also choose a scope for search. Then input the new line.

Upvotes: 1

rptwsthi
rptwsthi

Reputation: 10172

You can find for multiline text and replace it (cmd+opt+f) with new text. make sure to copy and paste multiline text as it is written on the Xcode file.

Replace multiple line text

Upvotes: 1

Related Questions