Skip to content

Instantly share code, notes, and snippets.

@tranquan
Last active April 25, 2024 01:54
Show Gist options
  • Star 72 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>
@kungpaogao
Copy link

thank you!

@MinuteReversal
Copy link

thank you!

@wooooooongs
Copy link

this is awesome!
thank you 🥹

@ethanmcrae
Copy link

My life is good again. Thank you 🙌

@Cecile-Lebleu
Copy link

Awesome! Thank you ✨

@MichalBastrzyk
Copy link

You came in clutch! Thank you 🙏

@naeimsf
Copy link

naeimsf commented Oct 17, 2023

perfect!

@darkphotonKN
Copy link

darkphotonKN commented Nov 20, 2023

Thanks, this works great, but I noticed you missed out on Command+D (Alt+D on windows, I think) where it highlights and selects multiple of the same text quickly on Vscode. Use it quite often as its a quick way to refactor stuff that needs to all be changed at the same time, so for those of you that are interested just:

  1. On Xcode go to the preferences > key bindings tab
  2. After selecting the nice and shiny VScode as the keybindings set thanks to our OP, search for "occurrence" on the top right filter bar.
  3. Change "Select Next Occurrence" to "CMD+D".
  4. Win

@jackHedaya
Copy link

this is awesome. thanks!

@rafaelolal
Copy link

Da goat!

@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 !

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