You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xcode自定义键绑定命令完整列表及官方API咨询

Get the Full Command List for DETextKeyBindingSet.plist & Official API Guide

Hey there! Let's break down what you need to build that handy { } shortcut and unlock more complex key bindings.

1. How to Get the Complete List of Usable Commands

Check the System's Default DETextKeyBindingSet.plist First

You can directly inspect the system file to see pre-defined bindings using Terminal:

plutil -p /System/Library/Frameworks/AppKit.framework/Versions/Current/Resources/DETextKeyBindingSet.plist

Or navigate to that path manually (right-click AppKit.framework > "Show Package Contents" to get into Resources) and open the plist with a text editor. But heads up—this only shows a subset of available commands. The real full list comes from the underlying AppKit framework.

Dig Into NSTextView's Methods for All Possible Commands

Every command you can use in key bindings is actually an Objective-C selector (method name) from NSTextView (and its subclasses, which power almost all text input fields on Mac). Any NSTextView method that takes no arguments or a single id parameter works for key bindings.

To see the full list, look up the NSTextView class reference—you'll find tons of useful commands beyond the ones you've already spotted, like:

  • moveToEndOfLine:
  • selectToBeginningOfParagraph:
  • pasteAsPlainText:
  • deleteBackward:
  • insertTab:

2. Official API Context

Apple doesn't have a standalone API doc just for text key bindings, but these commands are rooted in AppKit's Text System. The official resources you want are:

  • The NSTextView class reference: This is the source of all your bindable commands—every method listed here that fits the signature is fair game.
  • Apple's Text System Programming Guide: It explains how Mac's text handling works under the hood, including how key bindings map to these methods.

3. Example: Build Your { } Shortcut

To make a shortcut that inserts { } and drops the cursor right in the middle, edit your custom key bindings file (usually ~/Library/KeyBindings/DefaultKeyBinding.dict) and add this:

"^$[" = (
    insertText:"{",
    insertText:"}",
    moveBackward:,
);
  • ^$[ is the shortcut for Ctrl+Shift+[—swap this for any combo you prefer.
  • The array runs commands in order: insert {, insert }, then call moveBackward: to jump the cursor between them.

For something fancier, like wrapping the current word in brackets, try this:

"^$]" = (
    selectWord:,
    insertText:"{",
    yank:,
    insertText:"}",
    moveBackward:,
);

内容的提问来源于stack exchange,提问作者Charles Bentley

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:30:43