Skip to content

Instantly share code, notes, and snippets.

@tranquan
Last active April 22, 2025 17:38
Show Gist options
  • 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+Shift+O: Jump between functions (which is Show Document Items in Xcode)
  • Opt+Down/Up: Move lines up / down
  • Shift+Opt+Down: Duplicate lines
  • Ctr+X: Delete lines
  • F2: Refactor rename
  • F12: Go to definition
  • Shift+F12: Show callers (aka Go to references)

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>_invokeSourceEditorExtensionCommand:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandID</key>
				<string>IDESourceEditorExtension:com.charcoaldesign.SwiftFormat-for-Xcode.SourceEditorExtension,IDESourceEditorExtensionCommand:com.charcoaldesign.SwiftFormat-for-Xcode.SourceEditorExtension.FormatFileCommand</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>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>SwiftFormat</string>
				<key>Title</key>
				<string>Format File</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>_invokeSourceEditorExtensionCommand:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandID</key>
				<string>IDESourceEditorExtension:com.charcoaldesign.SwiftFormat-for-Xcode.SourceEditorExtension,IDESourceEditorExtensionCommand:com.charcoaldesign.SwiftFormat-for-Xcode.SourceEditorExtension.FormatSelectionCommand</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>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>SwiftFormat</string>
				<key>Title</key>
				<string>Format Selection</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>_invokeSourceEditorExtensionCommand:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandID</key>
				<string>IDESourceEditorExtension:com.charcoaldesign.SwiftFormat-for-Xcode.SourceEditorExtension,IDESourceEditorExtensionCommand:com.charcoaldesign.SwiftFormat-for-Xcode.SourceEditorExtension.LintFileCommand</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>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>SwiftFormat</string>
				<key>Title</key>
				<string>Lint File</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>duplicate:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEKit.CmdDefinition.Duplicate</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>editorContext_jumpToDefinition:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEKit.CmdDefinition.JumpToDefinition</string>
				<key>CommandID</key>
				<string>Xcode.IDEKit.CmdDefinition.JumpToDefinition</string>
				<key>Group</key>
				<string>Navigate 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>YES</string>
				<key>Title</key>
				<string>Jump to Definition</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>editorContext_jumpToDefinitionWithAlternate:</string>
				<key>Alternate</key>
				<string>YES</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEKit.CmdDefinition.JumpToDefinitionWithAlternate</string>
				<key>CommandID</key>
				<string>Xcode.IDEKit.CmdDefinition.JumpToDefinitionWithAlternate</string>
				<key>Group</key>
				<string>Navigate 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>YES</string>
				<key>Title</key>
				<string>Jump to Definition (option)</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>editorContext_jumpToDefinitionWithShiftPlusAlternate:</string>
				<key>Alternate</key>
				<string>YES</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEKit.CmdDefinition.JumpToDefinitionWithShiftPlusAlternate</string>
				<key>CommandID</key>
				<string>Xcode.IDEKit.CmdDefinition.JumpToDefinitionWithShiftPlusAlternate</string>
				<key>Group</key>
				<string>Navigate 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>YES</string>
				<key>Title</key>
				<string>Jump to Definition (shift+option)</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>newFolder:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>IDENewGrouping</string>
				<key>CommandID</key>
				<string>Xcode.IDEKit.CmdDefinition.NewFolder</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>~@n</string>
				<key>Navigation</key>
				<string>NO</string>
				<key>Parent Title</key>
				<string>New</string>
				<key>Title</key>
				<string>Folder</string>
			</dict>
			<dict>
				<key>Action</key>
				<string>openQuickly:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEKit.CmdDefinition.OpenQuickly</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>CommandGroupID</key>
				<string>Xcode.IDEKit.CmdDefinition.PageSetup</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>CommandGroupID</key>
				<string>Xcode.IDEKit.CmdDefinition.Print</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>CommandGroupID</key>
				<string>Xcode.IDEKit.CmdDefinition.ShowDocumentItemsMenu</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>CommandGroupID</key>
				<string>Xcode.IDEKit.CmdDefinition.ToggleBreakpointAtCurrentLine</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>
			<dict>
				<key>Action</key>
				<string>jumpToCallers:</string>
				<key>Alternate</key>
				<string>NO</string>
				<key>CommandGroupID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.ShowCallers</string>
				<key>CommandID</key>
				<string>Xcode.IDEPegasusSourceEditor.CmdDefinition.ShowCallers</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>Title</key>
				<string>Show Callers…</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>moveParagraphBackwardAndModifySelection:</string>
				<string>moveParagraphForwardAndModifySelection:</string>
				<array>
					<string>moveBackward:</string>
					<string>moveToBeginningOfParagraph:</string>
				</array>
				<array>
					<string>moveForward:</string>
					<string>moveToEndOfParagraph:</string>
				</array>
				<string>selectToMark:</string>
				<string>swapWithMark:</string>
				<string>scrollToBeginningOfDocument:</string>
				<string>scrollToEndOfDocument:</string>
			</array>
			<key>^x</key>
			<string>deleteLine:</string>
			<key></key>
			<string>deleteForward:</string>
		</dict>
		<key>Version</key>
		<integer>3</integer>
	</dict>
</dict>
</plist>
@yagudaev
Copy link

Thank you. Xcode no longer has to be hell

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