Skip to content

Instantly share code, notes, and snippets.

@b-outlaw
Created May 1, 2019 20:58
Show Gist options
  • Save b-outlaw/4fe1e3ee3dd21e14f43cf7aade98677f to your computer and use it in GitHub Desktop.
Save b-outlaw/4fe1e3ee3dd21e14f43cf7aade98677f to your computer and use it in GitHub Desktop.
Xcode – Insert Newline Before/After
  1. Open below directory in Finder with Cmnd + Shift + G
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/
  1. Open IDETextKeyBindingSet.plist with a text editor (not Xcode's plist editor).

  2. Add this in:

<key>Insert Newline Before</key>
<string>moveUp:, moveToEndOfLine:, insertNewline:</string>
<key>Insert Newline After</key>
<string>moveToEndOfLine:, insertNewline:</string>
  1. Open Xcode and go to Xcode preferences -> Key Bindings Search for "insert newline"

  2. Add shortcuts for new commands.

@wonderbit
Copy link

This made my day, thank you!

@mahiznan
Copy link

mahiznan commented Apr 9, 2023

Unable to edit the IDETextKeyBindingSet.plist file with Xcode 14.3 even with sudo command. Any work around?

@b-outlaw
Copy link
Author

b-outlaw commented Apr 9, 2023

I haven’t tried yet. Good reminder for me to upgrade to Ventura though. I’ll try to update this tomorrow.

@b-outlaw
Copy link
Author

b-outlaw commented Apr 9, 2023

I navigated (command line) to the proper directory and ran open IDETextKeyBindingSet.plist. That opened the file in Xcode and I added the keys and values there. It didn’t seem to save but when I reopened the file it had been changed and I was able to set up my Key Bindings.

@mahiznan
Copy link

mahiznan commented Apr 9, 2023

Screenshot 2023-04-09 at 6 41 23 PM

When I add the key, while closing the window it is prompting with message as permission denied. I am the root user. Even I can't close that window normally after removing that key as well. I forcefully closing Xcode

@mikelluzuriaga
Copy link

mikelluzuriaga commented May 1, 2023

@mahiznan You have to give edit permission to that file (not sure how to do that, chmod on terminal I guess), or copy it and paste to other location (like desktop), open and edit, then paste into the same location (it will ask for the password of the root user), or you can do "sudo nano IDETextKeyBindingSet.plist" with terminal.

@kollein
Copy link

kollein commented Sep 27, 2023

Thanks @mikelluzuriaga , It works well when i copy to another place > edit > replace file in the destination.

@vladmircan
Copy link

Besides chmod, you can give permission to a file by opening its info and modifying the Sharing & Permissions section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment