Skip to content

Instantly share code, notes, and snippets.

@tranquan
Last active May 8, 2024 13:05
Show Gist options
  • Star 73 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save tranquan/b15a4502930e4c8649bc1dab5c1d2173 to your computer and use it in GitHub Desktop.
Save tranquan/b15a4502930e4c8649bc1dab5c1d2173 to your computer and use it in GitHub Desktop.
Xcode KeyBindings as VSCode

Overview

To setup some key bindings in Xcode with the same like VSCode

Add duplicate lines

Add this to /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist Thanks to: https://gist.github.com/emotality/b1bcb2bb8a07921f9c8cad1c969daedf

<key>Duplication</key>
<dict>
    <key>Duplicate Current Line</key>
    <string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
    <key>Duplicate Lines</key>
    <string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
    <key>Delete Line</key>
    <string>selectLine:, deleteBackward:</string>
</dict>

Add VSCode keybindings

  • Cmd+P: quick open file
  • Cmd+Opt+O: jump between functions (which is Show Document Items in Xcode)
  • Opt+down/up: move lines
  • Shift+Opt+down: duplicate lines
  • Ctr+X: delete lines
  • Refactor rename: F2

Add this to ~/Library/Developer/Xcode/UserData/KeyBindings/VSCode.idekeybindings Then, select VSCode in Xcode/Preferences/KeyBindings

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Menu Key Bindings</key>
	<dict>
		<key>Key Bindings</key>
		<array>
			<dict>
				<key>Action</key>
				<string>duplicate:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandID</key>
				<string>Xcode.IDEKit.CmdDefinition.Duplicate</string>
				<key>Group</key>
				<string>Edit Menu</string>
				<key>GroupID</key>
				<string>Xcode.IDEKit.MenuDefinition.Main</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Keyboard Shortcut</key>
				<string>~$</string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Title</key>
				<string>Duplicate</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>openQuickly:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandID</key>
				<string>Xcode.IDEKit.CmdDefinition.OpenQuickly</string>
				<key>Group</key>
				<string>File Menu</string>
				<key>GroupID</key>
				<string>Xcode.IDEKit.MenuDefinition.Main</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Keyboard Shortcut</key>
				<string>@p</string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Title</key>
				<string>Open Quickly…</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>runPageLayout:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandID</key>
				<string>Xcode.IDEKit.CmdDefinition.PageSetup</string>
				<key>Group</key>
				<string>File Menu</string>
				<key>GroupID</key>
				<string>Xcode.IDEKit.MenuDefinition.Main</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Title</key>
				<string>Page Setup…</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>printDocument:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandID</key>
				<string>Xcode.IDEKit.CmdDefinition.Print</string>
				<key>Group</key>
				<string>File Menu</string>
				<key>GroupID</key>
				<string>Xcode.IDEKit.MenuDefinition.Main</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Title</key>
				<string>Print…</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>showDocumentItemsMenu:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandID</key>
				<string>Xcode.IDEKit.CmdDefinition.ShowDocumentItemsMenu</string>
				<key>Group</key>
				<string>View Menu</string>
				<key>GroupID</key>
				<string>Xcode.IDEKit.MenuDefinition.Main</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Keyboard Shortcut</key>
				<string>$@O</string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>Editor</string>
				<key>Title</key>
				<string>Show Document Items</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>toggleBreakpointAtCurrentLine:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandID</key>
				<string>Xcode.IDEKit.CmdDefinition.ToggleBreakpointAtCurrentLine</string>
				<key>Group</key>
				<string>Debug Menu</string>
				<key>GroupID</key>
				<string>Xcode.IDEKit.MenuDefinition.Main</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Keyboard Shortcut</key>
				<string></string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>Breakpoints</string>
				<key>Title</key>
				<string>Create Breakpoint at Current Line</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>moveCurrentLineDown:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.MoveLineDown</string>
				<key>CommandID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.MoveLineDown</string>
				<key>Group</key>
				<string>Editor Menu for Asset Catalog Comparison</string>
				<key>GroupID</key>
				<string>Xcode.DeltaComparisonEditor.MenuDefinition.Editor</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Keyboard Shortcut</key>
				<string>~</string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>Structure</string>
				<key>Title</key>
				<string>Move Line Down</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>moveCurrentLineDown:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.MoveLineDown</string>
				<key>CommandID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.MoveLineDown</string>
				<key>Group</key>
				<string>Editor Menu for Playground</string>
				<key>GroupID</key>
				<string>Xcode.IDEPlaygroundEditor.MenuDefinition.Editor</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Keyboard Shortcut</key>
				<string>~</string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>Structure</string>
				<key>Title</key>
				<string>Move Line Down</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>moveCurrentLineDown:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.MoveLineDown</string>
				<key>CommandID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.MoveLineDown</string>
				<key>Group</key>
				<string>Editor Menu for Source Code</string>
				<key>GroupID</key>
				<string>Xcode.IDEPegasusSourceEditor.MenuDefinition.Editor</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Keyboard Shortcut</key>
				<string>~</string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>Structure</string>
				<key>Title</key>
				<string>Move Line Down</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>moveCurrentLineUp:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.MoveLineUp</string>
				<key>CommandID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.MoveLineUp</string>
				<key>Group</key>
				<string>Editor Menu for Asset Catalog Comparison</string>
				<key>GroupID</key>
				<string>Xcode.DeltaComparisonEditor.MenuDefinition.Editor</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Keyboard Shortcut</key>
				<string>~</string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>Structure</string>
				<key>Title</key>
				<string>Move Line Up</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>moveCurrentLineUp:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.MoveLineUp</string>
				<key>CommandID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.MoveLineUp</string>
				<key>Group</key>
				<string>Editor Menu for Playground</string>
				<key>GroupID</key>
				<string>Xcode.IDEPlaygroundEditor.MenuDefinition.Editor</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Keyboard Shortcut</key>
				<string>~</string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>Structure</string>
				<key>Title</key>
				<string>Move Line Up</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>moveCurrentLineUp:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.MoveLineUp</string>
				<key>CommandID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.MoveLineUp</string>
				<key>Group</key>
				<string>Editor Menu for Source Code</string>
				<key>GroupID</key>
				<string>Xcode.IDEPegasusSourceEditor.MenuDefinition.Editor</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Keyboard Shortcut</key>
				<string>~</string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>Structure</string>
				<key>Title</key>
				<string>Move Line Up</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>renameRefactor:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.Refactor.Rename</string>
				<key>CommandID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.Refactor.Rename</string>
				<key>Group</key>
				<string>Editor Menu for Asset Catalog Comparison</string>
				<key>GroupID</key>
				<string>Xcode.DeltaComparisonEditor.MenuDefinition.Editor</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Keyboard Shortcut</key>
				<string></string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>Refactor</string>
				<key>Title</key>
				<string>Rename…</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>renameRefactor:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.Refactor.Rename</string>
				<key>CommandID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.Refactor.Rename</string>
				<key>Group</key>
				<string>Editor Menu for Playground</string>
				<key>GroupID</key>
				<string>Xcode.IDEPlaygroundEditor.MenuDefinition.Editor</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Keyboard Shortcut</key>
				<string></string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>Refactor</string>
				<key>Title</key>
				<string>Rename…</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>renameRefactor:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.Refactor.Rename</string>
				<key>CommandID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.Refactor.Rename</string>
				<key>Group</key>
				<string>Editor Menu for Source Code</string>
				<key>GroupID</key>
				<string>Xcode.IDEPegasusSourceEditor.MenuDefinition.Editor</string>
				<key>GroupedAlternate</key>
				<string>NO</string>
				<key>Keyboard Shortcut</key>
				<string></string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>Refactor</string>
				<key>Title</key>
				<string>Rename…</string>
			</dict>
		</array>
		<key>Version</key>
		<integer>3</integer>
	</dict>
	<key>Text Key Bindings</key>
	<dict>
		<key>Key Bindings</key>
		<dict>
			<key></key>
			<array>
				<string>scrollToEndOfDocument:</string>
				<string>scrollToBeginningOfDocument:</string>
				<string>selectToMark:</string>
				<string>swapWithMark:</string>
				<string>moveParagraphBackwardAndModifySelection:</string>
				<array>
					<string>moveBackward:</string>
					<string>moveToBeginningOfParagraph:</string>
				</array>
				<array>
					<string>moveForward:</string>
					<string>moveToEndOfParagraph:</string>
				</array>
				<string>moveParagraphForwardAndModifySelection:</string>
			</array>
			<key>^x</key>
			<string>deleteLine:</string>
			<key></key>
			<string>deleteForward:</string>
		</dict>
		<key>Version</key>
		<integer>3</integer>
	</dict>
</dict>
</plist>
@alevani
Copy link

alevani commented Jan 9, 2024

Awesome!! Thanks man

@alexsafayan
Copy link

alexsafayan commented Apr 13, 2024

If anyone has trouble editing IDETextKeyBindingSet.plist using terminal and nano: copy IDETextKeyBindingSet.plist to your desktop, edit it, and replace the original in /Resources with it.

@alexsafayan
Copy link

Thanks @darkphotonKN !

@jacinyan
Copy link

jacinyan commented May 7, 2024

Thanks a ton!

@f0ursecond
Copy link

thanks

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