Patrick Tsai
Patrick Tsai

Reputation: 366

Open a new line below current line in Xcode

Is there any easy way to open a new line below current line in Xcode text editor? Currently I have to press cmd+right and enter for this purpose. Eclipse (Shift+Enter) and vim (o) can do that with simple key combination.

Upvotes: 16

Views: 8910

Answers (4)

meerkat_citronella
meerkat_citronella

Reputation: 298

I found that moveToEndOfLine:, insertNewline: did not work for me. Instead, this worked moveToEndOfLine:, insertLineBreak:. I am using Xcode 13.4.1

Upvotes: 1

Nasib
Nasib

Reputation: 1549

The answer is

1. open this file

/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist

2. option click (context menu) and select Add Row

3. Give any name (e.g My Custom) choose **Dictionary as it's type

4. click + icon on this new dictionary. a new field will appear, enter your preferred name (e.g insert new line below).

5. enter moveToEndOfLine:, insertNewline: as it's value

6. save the file.

7. quit and relaunch Xcode

8. open preferences, go to key bindings and search for your name insert new line below

assign a shortcut.

enjoy!

enter image description here

enter image description here

NOTES if you have permissions problem in saving the file. just copy the file to your desktop, edit it, and then move the file to the location /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/

Upvotes: 3

c0ming
c0ming

Reputation: 3543

You can take a look at this tutorial about how to add custom keyboard shortcut in Xcode ---Xcode duplicate line, then just add a new key-value Insert New Line Below Current Line moveToEndOfLine:, insertNewline: in IDETextKeyBindingSet.plist file, at last config your Key Bindings (like Shift+Enter) in Xcode.

Upvotes: 11

AWF4vk
AWF4vk

Reputation: 5890

I don't think XCode supports that shortcut.

Check the Key Bindings preferences. Search for "line" under the Text tab.

There are lots of "Insert Newline" commands for which you can set key combos. There's Ctrl+o, Cmd+Enter, Opt+Enter, etc. But I don't think it's possible to do natively.

Upvotes: 3

Related Questions