Git, CocoaPods, Xcode, Shell

[iOS - xcode] 커스텀 단축키 만드는 방법, move to next line 커스텀 단축키 만들기 (custom shortcut)

jake-kim 2023. 2. 25. 23:26

커스텀 단축키: 아래로 이동

커스텀 단축키 만드는 방법

  • Xcode에서는 여러가지 단축 키워드가 존재하는데, 이를 조합하여 다양한 단축키 생성이 가능
  • 디폴트로 주어진 단축키를 확인하는 가장 간편한 방법은 Xcode에서 확인
    • 단축키: cmd + , 입력 후 Key Bindings 탭 클릭
  • 하지만 이곳에서는 커스텀이 불가능하여 코드 베이스로 접근하여 수정이 필요

커스텀 방법

  • 위 key bindings 탭에서 보이는 것들은 모두 코드 베이스로 제공하는 것들이므로 코드 베이스 부분을 확인
  • 위 파일은 아래 경로에 위치
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist

 

  • 파일 수정을 위해 Desktop에 잠시 복사
cp /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist ~/Desktop/
  • 아래와 같이 dict로 감싼 후 key-string으로 되어 있는 형태
    • key부분은 사용자에게 보이는 문자열값
    • value부분이 이미 주어진 키워드를 조합하여 커스텀 단축키 생성이 가능 
<?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>Cancellation</key>
    <dict>
        <key>Cancel</key>
        <string>cancelOperation:</string>
    </dict>
    
    ...
    
    <key>Writing Direction</key>
    <dict>
        <key>Make Base Writing Direction Left to Right</key>
        <string>makeBaseWritingDirectionLeftToRight:</string>
        ...
        <key>Make Text Writing Direction Right to Left</key>
        <string>makeTextWritingDirectionRightToLeft:</string>
    </dict>
</dict>
</plist>

 

move to next line 커스텀 단축키 만들기

  • 위에서 알아본 대로 Desktop으로 shortcut 관련 코드를 복사
cp /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist ~/Desktop/
  • 처음 key에는 dict의 이름을 입력
  • dict안의 key-value쌍에서, key는 단축키의 이름을 입력하고 value에는 키워드를 조합하여 입력
    • value에는 콜론과 콤마를 적절히 사용하여 조합
    • 오른쪽으로 이동하는 단축키 키워드 아래쪽으로 이동하는 단축키 키워드를 콤마로 추가
    <key>My Custom Actions</key>
    <dict>
    <key>Move to next line</key>
    <string>moveToEndOfLine:, moveDown:</string>
    </dict>
  • Desktop에 있는 이 수정된 파일을 다시 원래 위치로 복사
sudo cp ~/Desktop/IDETextKeyBindingSet.plist /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
  • Xcode 재부팅 후 cmd + , 으로 환경설정창을 열고 Key Bindings 탭을 클릭
    • Move to next line 을 검색하여 key에 단축키 입력

(완료)

만약 Move to next line을 아래로 이동하면서 enter까지 입력되게 하려면 아래처럼 사용

<string>moveToEndOfLine:, insertNewline:</string>

(단축키 관련 전체 코드)

<?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>Cancellation</key>
    <dict>
        <key>Cancel</key>
        <string>cancelOperation:</string>
    </dict>
    <key>Transformations</key>
    <dict>
        <key>Capitalize Word</key>
        <string>capitalizeWord:</string>
        <key>Lowercase Word</key>
        <string>lowercaseWord:</string>
        <key>Uppercase Word</key>
        <string>uppercaseWord:</string>
        <key>Transpose</key>
        <string>transpose:</string>
    </dict>
    <key>Code Completion</key>
    <dict>
        <key>Select Next Completion</key>
        <string>nextCompletion:</string>
        <key>Select Previous Completion</key>
        <string>previousCompletion:</string>
        <key>Show Completion List</key>
        <string>complete:</string>
    </dict>
    <key>Deletions</key>
    <dict>
        <key>Delete</key>
        <string>delete:</string>
        <key>Delete Backward</key>
        <string>deleteBackward:</string>
        <key>Delete Backward by Decomposing Previous Character</key>
        <string>deleteBackwardByDecomposingPreviousCharacter:</string>
        <key>Delete Forward</key>
        <string>deleteForward:</string>
        <key>Delete Subword Backward</key>
        <string>deleteSubWordBackward:</string>
        <key>Delete Subword Forward</key>
        <string>deleteSubWordForward:</string>
        <key>Delete Expression Backward</key>
        <string>deleteExpressionBackward:</string>
        <key>Delete Expression Forward</key>
        <string>deleteExpressionForward:</string>
        <key>Delete Line</key>
        <string>deleteLine:</string>
        <key>Delete Paragraph</key>
        <string>deleteParagraph:</string>
        <key>Delete Word Backward</key>
        <string>deleteWordBackward:</string>
        <key>Delete Word Forward</key>
        <string>deleteWordForward:</string>
        <key>Delete to Beginning of Document</key>
        <string>deleteToBeginningOfDocument:</string>
        <key>Delete to Beginning of Line</key>
        <string>deleteToBeginningOfLine:</string>
        <key>Delete to Beginning of Paragraph</key>
        <string>deleteToBeginningOfParagraph:</string>
        <key>Delete to Beginning of Text</key>
        <string>deleteToBeginningOfText:</string>
        <key>Delete to End of Document</key>
        <string>deleteToEndOfDocument:</string>
        <key>Delete to End of Line</key>
        <string>deleteToEndOfLine:</string>
        <key>Delete to End of Paragraph</key>
        <string>deleteToEndOfParagraph:</string>
        <key>Delete to End of Text</key>
        <string>deleteToEndOfText:</string>
        <key>Join Paragraphs</key>
        <string>joinParagraphs:</string>
        <key>Join Paragraphs Preserving Whitespaces</key>
        <string>joinParagraphsPreservingWhitespaces:</string>
    </dict>
    <key>Find &amp; Replace</key>
    <dict>
        <key>Find Next</key>
        <string>findNext:</string>
        <key>Find Previous</key>
        <string>findPrevious:</string>
        <key>Replace</key>
        <string>replace:</string>
        <key>Replace All</key>
        <string>replaceAll:</string>
        <key>Replace and Find Next</key>
        <string>replaceAndFindNext:</string>
        <key>Replace and Find Previous</key>
        <string>replaceAndFindPrevious:</string>
    </dict>
    <key>Insertions and Indentations</key>
    <dict>
        <key>Indent</key>
        <string>indent:</string>
        <key>Insert Backtab</key>
        <string>insertBacktab:</string>
        <key>Insert Container Break</key>
        <string>insertContainerBreak:</string>
        <key>Insert Double Quote without Extra Action</key>
        <string>insertDoubleQuoteIgnoringSubstitution:</string>
        <key>Insert Line Break</key>
        <string>insertLineBreak:</string>
        <key>Insert Newline</key>
        <string>insertNewline:</string>
        <key>Insert Newline and Leave Selection Before It</key>
        <string>insertNewlineIgnoringFieldEditor:, moveBackward:</string>
        <key>Insert Newline without Extra Action</key>
        <string>insertNewlineIgnoringFieldEditor:</string>
        <key>Insert Paragraph Separator</key>
        <string>insertParagraphSeparator:</string>
        <key>Insert Single Quote without Extra Action</key>
        <string>insertSingleQuoteIgnoringSubstitution:</string>
        <key>Insert Slash</key>
        <string>insertRightToLeftSlash:</string>
        <key>Insert Tab</key>
        <string>insertTab:</string>
        <key>Insert Tab without Extra Action</key>
        <string>insertTabIgnoringFieldEditor:</string>
    </dict>
    <key>Mark &amp; Yank</key>
    <dict>
        <key>Delete to Mark</key>
        <string>deleteToMark:</string>
        <key>Select to Mark</key>
        <string>selectToMark:</string>
        <key>Set Mark</key>
        <string>setMark:</string>
        <key>Swap with Mark</key>
        <string>swapWithMark:</string>
        <key>Yank</key>
        <string>yank:</string>
        <key>Yank and Select</key>
        <string>yankAndSelect:</string>
    </dict>
    <key>Scrolling</key>
    <dict>
        <key>Center Selection in Visible Area</key>
        <string>centerSelectionInVisibleArea:</string>
        <key>Scroll Left</key>
        <string>scrollTabWidthLeft:</string>
        <key>Scroll Line Down</key>
        <string>scrollLineDown:</string>
        <key>Scroll Line Up</key>
        <string>scrollLineUp:</string>
        <key>Scroll Page Down</key>
        <string>scrollPageDown:</string>
        <key>Scroll Page Up</key>
        <string>scrollPageUp:</string>
        <key>Scroll Right</key>
        <string>scrollTabWidthRight:</string>
        <key>Scroll to Beginning of Document</key>
        <string>scrollToBeginningOfDocument:</string>
        <key>Scroll to End of Document</key>
        <string>scrollToEndOfDocument:</string>
    </dict>
    <key>Selection</key>
    <dict>
        <key>Move Backward</key>
        <string>moveBackward:</string>
        <key>Move Backward Extending Selection</key>
        <string>moveBackwardAndModifySelection:</string>
        <key>Move Down</key>
        <string>moveDown:</string>
        <key>Move Down Extending Selection</key>
        <string>moveDownAndModifySelection:</string>
        <key>Move Forward</key>
        <string>moveForward:</string>
        <key>Move Forward Extending Selection</key>
        <string>moveForwardAndModifySelection:</string>
        <key>Move Left</key>
        <string>moveLeft:</string>
        <key>Move Left Extending Selection</key>
        <string>moveLeftAndModifySelection:</string>
        <key>Move Paragraph Backward</key>
        <string>moveBackward:, moveToBeginningOfParagraph:</string>
        <key>Move Paragraph Backward Extending Selection</key>
        <string>moveParagraphBackwardAndModifySelection:</string>
        <key>Move Paragraph Forward</key>
        <string>moveForward:, moveToEndOfParagraph:</string>
        <key>Move Paragraph Forward Extending Selection</key>
        <string>moveParagraphForwardAndModifySelection:</string>
        <key>Move Right</key>
        <string>moveRight:</string>
        <key>Move Right Extending Selection</key>
        <string>moveRightAndModifySelection:</string>
        <key>Move Subword Backward</key>
        <string>moveSubWordBackward:</string>
        <key>Move Subword Backward Extending Selection</key>
        <string>moveSubWordBackwardAndModifySelection:</string>
        <key>Move Subword Forward</key>
        <string>moveSubWordForward:</string>
        <key>Move Subword Forward Extending Selection</key>
        <string>moveSubWordForwardAndModifySelection:</string>
        <key>Move Expression Left</key>
        <string>moveExpressionBackward:</string>
        <key>Move Expression Left Extending Selection</key>
        <string>moveExpressionBackwardAndModifySelection:</string>
        <key>Move Expression Right</key>
        <string>moveExpressionForward:</string>
        <key>Move Expression Right Extending Selection</key>
        <string>moveExpressionForwardAndModifySelection:</string>
        <key>Move Up</key>
        <string>moveUp:</string>
        <key>Move Up Extending Selection</key>
        <string>moveUpAndModifySelection:</string>
        <key>Move Word Backward</key>
        <string>moveWordBackward:</string>
        <key>Move Word Backward Extending Selection</key>
        <string>moveWordBackwardAndModifySelection:</string>
        <key>Move Word Forward</key>
        <string>moveWordForward:</string>
        <key>Move Word Forward Extending Selection</key>
        <string>moveWordForwardAndModifySelection:</string>
        <key>Move Word Left</key>
        <string>moveWordLeft:</string>
        <key>Move Word Left Extending Selection</key>
        <string>moveWordLeftAndModifySelection:</string>
        <key>Move Word Right</key>
        <string>moveWordRight:</string>
        <key>Move Word Right Extending Selection</key>
        <string>moveWordRightAndModifySelection:</string>
        <key>Move to Beginning of Document</key>
        <string>moveToBeginningOfDocument:</string>
        <key>Move to Beginning of Document Extending Selection</key>
        <string>moveToBeginningOfDocumentAndModifySelection:</string>
        <key>Move to Beginning of Line</key>
        <string>moveToBeginningOfLine:</string>
        <key>Move to Beginning of Line Extending Selection</key>
        <string>moveToBeginningOfLineAndModifySelection:</string>
        <key>Move to Beginning of Paragraph</key>
        <string>moveToBeginningOfParagraph:</string>
        <key>Move to Beginning of Paragraph Extending Selection</key>
        <string>moveToBeginningOfParagraphAndModifySelection:</string>
        <key>Move to Beginning of Text</key>
        <string>moveToBeginningOfText:</string>
        <key>Move to Beginning of Text Extending Selection</key>
        <string>moveToBeginningOfTextAndModifySelection:</string>
        <key>Move to End of Document</key>
        <string>moveToEndOfDocument:</string>
        <key>Move to End of Document Extending Selection</key>
        <string>moveToEndOfDocumentAndModifySelection:</string>
        <key>Move to End of Line</key>
        <string>moveToEndOfLine:</string>
        <key>Move to End of Line Extending Selection</key>
        <string>moveToEndOfLineAndModifySelection:</string>
        <key>Move to End of Paragraph</key>
        <string>moveToEndOfParagraph:</string>
        <key>Move to End of Paragraph Extending Selection</key>
        <string>moveToEndOfParagraphAndModifySelection:</string>
        <key>Move to End of Text</key>
        <string>moveToEndOfText:</string>
        <key>Move to End of Text Extending Selection</key>
        <string>moveToEndOfTextAndModifySelection:</string>
        <key>Move to Left End of Line</key>
        <string>moveToLeftEndOfLine:</string>
        <key>Move to Left End of Line Extending Selection</key>
        <string>moveToLeftEndOfLineAndModifySelection:</string>
        <key>Move to Right End of Line</key>
        <string>moveToRightEndOfLine:</string>
        <key>Move to Right End of Line Extending Selection</key>
        <string>moveToRightEndOfLineAndModifySelection:</string>
        <key>Move Half Page Down</key>
        <string>halfPageDown:</string>
        <key>Move Half Page Down Extending Selection</key>
        <string>halfPageDownAndModifySelection:</string>
        <key>Move Half Page Up</key>
        <string>halfPageUp:</string>
        <key>Move Half Page Up Extending Selection</key>
        <string>halfPageUpAndModifySelection:</string>
        <key>Move Page Down</key>
        <string>pageDown:</string>
        <key>Move Page Down Extending Selection</key>
        <string>pageDownAndModifySelection:</string>
        <key>Move Page Up</key>
        <string>pageUp:</string>
        <key>Move Page Up Extending Selection</key>
        <string>pageUpAndModifySelection:</string>
        <key>Select All</key>
        <string>selectAll:</string>
        <key>Select Line</key>
        <string>selectLine:</string>
        <key>Select Paragraph</key>
        <string>selectParagraph:</string>
        <key>Select Word</key>
        <string>selectWord:</string>
    </dict>
    <key>Undo/Redo</key>
    <dict>
        <key>Redo</key>
        <string>redo:</string>
        <key>Undo</key>
        <string>undo:</string>
    </dict>
    <key>Writing Direction</key>
    <dict>
        <key>Make Base Writing Direction Left to Right</key>
        <string>makeBaseWritingDirectionLeftToRight:</string>
        <key>Make Base Writing Direction Natural</key>
        <string>makeBaseWritingDirectionNatural:</string>
        <key>Make Base Writing Direction Right to Left</key>
        <string>makeBaseWritingDirectionRightToLeft:</string>
        <key>Make Text Writing Direction Left to Right</key>
        <string>makeTextWritingDirectionLeftToRight:</string>
        <key>Make Text Writing Direction Natural</key>
        <string>makeTextWritingDirectionNatural:</string>
        <key>Make Text Writing Direction Right to Left</key>
        <string>makeTextWritingDirectionRightToLeft:</string>
    </dict>

    <key>My Custom Actions</key>
    <dict>
    <key>Move to next line</key>
    <string>moveToEndOfLine:, insertNewline:</string>
    </dict>
</dict>
</plist>

* 참고

https://stackoverflow.com/questions/34558727/xcode-go-to-next-line-hotkey-like-intellijs-shift-enter