5

I get indentation issues when I copy few lines and paste it. Xcode does not copy indentation properly or applies another indentations.

As shown in below images, I copied first function and pasted which is second function. Indentation are reapplied except for first line.

enter image description here

I played with Xcode indentation settings but could not solve it neither do I have any clue why this happens.

Below are 2 indentation settings I tried.

enter image description here

enter image description here

Do anybody see anything wrong in above settings?

Khaled Barazi
8,7516 gold badges44 silver badges63 bronze badges
asked Nov 29, 2013 at 5:36
2
  • do you simply paste with command-V (plain ol' paste) or do you use the paste-and-preserve-formatting Xcode edit menu choice (which has a crazy key combination including command-V)?? Commented Nov 29, 2013 at 5:44
  • @MichaelDautermann I use command-V. Commented Nov 29, 2013 at 5:59

5 Answers 5

6

In Xcode preferences, Key Bindings tab, redefine ⌘-V to "Paste and Preserve Formatting" and ⌘-option-shift-V to "Paste". Then ⌘-V will do "Paste and Preserve Formatting" which is what you want.

answered Jun 17, 2014 at 22:36
Sign up to request clarification or add additional context in comments.

Comments

0

Try turning off Auto-Indentation. That way, Xcode doesn't remove formatting.

answered Dec 19, 2013 at 6:11

Comments

0

That was when i customized indentation in Swift and then get back to Obj-C. Nothing with changing preferences helped. Just fully restart xcode.

answered Dec 20, 2016 at 8:55

Comments

-1

With cut and paste, you have to actually tell xcode to indent after the pasting.

⌘ A and then Control I. The first one select the whole class contents (when the cursor is inside) and the second one indents it based on your indent preferences.

Hope this helps.

answered Nov 29, 2013 at 5:53

6 Comments

This added unnecessary indents to almost all lines in a class.
This will do whatever you set your indentation setting to be. So if you change "indent width" to 3 spaces and then repeat, it will change indentation to 3 spaces. Alternatively ⌘ z to undo and only select the code you want to indent and then Control I.
I don't want that indents added when pasting the code. Those are unnecessary. I want it to paste exactly same as what I copied.
Then I would use @MichaelDautermann answer when pasting: Edit + "paste and preserve formatting"
I don't want to use that as it involves pressing 4 keys at a time. And till today command-v used to work in Xcode5.
|
-3

I just checked Xcode settings in another mac and made changes to match that and solved the issue. Sorry I don't remember what were they as it has been too long.

answered Mar 9, 2014 at 7:57

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.