developer tip

Xcode 중복 라인

optionbox 2020. 7. 26. 12:54
반응형

Xcode 중복 라인


이다Duplicate (기본 바로 가기와 편집 메뉴의 명령은 D), 그러나 (로는 누나가 엑스 코드의 인터페이스 빌더 부분에 중복에 대한 의미 지적했다).

그렇다면 Xcode 4에서 한 줄을 어떻게 쉽게 복제합니까?


Xcode 3 ...에 대한 관련 질문 (작동 답변 포함) ... Xcode 4에서는 작동하지 않습니다.


왜 그냥 복사해서 붙여 넣기를하지 않습니까?

그것은 지루하고 너무 많은 곡예를 수반하기 때문에 :

(1) : 라인 시작 한 다음 Enter 키를 눌러 이동 ⇧^E, 다음으로 복사 ⌘C, 새로운 라인으로 이동, 커서를 alligning, 그리고 마지막 으로 붙여 넣기 ⌘V;

또는 (2) : ^A(커서를 행 시작으로 ^SPACE설정 ), (설정 표시), ^E(커서를 행 끝으로 설정), ⇧^W( Select to Mark; 사용자 정의), 복사, 줄 바꿈 등

Frank Schröder ( 관련 질문에서 )는 다음 같이 말합니다.

요점은 Cmd-C / Cmd-V 단축키를 사용하지 않는 것입니다.


  1. 힘의 어두운면이 들어있는이 폴더로 이동하십시오.

    • Xcode 4.2 이하 : /Developer/Library/PrivateFrameworks/IDEKit.framework/Resources
    • Xcode 4.3 이상 : /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources.
  2. 를 엽니 다 IDETextKeyBindingSet.plist.

  3. 아래 스크린 샷으로 새 사전과 새 명령 항목을 추가하십시오 (원하는 이름을 지정하십시오). plist 편집

    그건 : selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:

  4. Xcode를 다시 시작하고 환경 설정-키 바인딩으로 이동하여 명령을 검색하십시오.

  5. 명령의 키 조합을 설정하십시오. 키 바인딩

  6. 마지막으로 Xcode에서 키 바인딩의 힘을 발휘하십시오. 즐기십시오!


중복 줄 추가 Xcode 버전 7.1, 7.3, 7.3.1 8.0, 8.1, 8.2, 8.3 및 9.0, 9.1, 9.2, 10.0, 10.1에서도 작동합니다.

2019 년 10.2.1에서도 작동

다음 파일을 편집하려면 persiomission을 부여하십시오. 대부분의 경우 OS에서 파일을 편집 할 수 없습니다.

sudo chmod 666 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist

sudo chmod 777 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/

다음 파일을 편집하십시오.

/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist

다음 명령을 작성하여.

open /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist

다음 xml 스 니펫을 추가하십시오.

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

편집 된 파일의 스크린 샷.

여기에 이미지 설명을 입력하십시오

Xcode를 다시 시작하고으로 이동하여 Preferences - Key Bindings입력 한 명령 (중복 라인 및 현재 라인 복제)을 검색하십시오.

여기에 이미지 설명을 입력하십시오

그게 다야.


오늘 저는 줄과 선택을 삭제하고 복제하는 Xcode 5 용 매우 작은 플러그인을 작성했습니다.

내 GitHub 저장소에서 다운로드 할 수 있습니다 : XcodeKit Plugin-https : //github.com/ptfly/XcodeKit


@Hailei의 대답은 꽤 좋았지 만 클립 보드 내용을 복제하는 것 (중복 된 줄의 내용으로 채워진 채 남겨 둔)의 불행한 부작용이 있었으며, 이는 내가 피하려고했던 수동 복사 / 붙여 넣기 접근법의 일부입니다. .

그래서 명령 순서를 다음과 같이 변경했습니다.

moveToBeginningOfLine:,
deleteToEndOfLine:,
yank:,
insertNewline:,
moveToBeginningOfLine:,
yank:

에서 제외 된 yank:것으로 NSTextKillRingSize설정 하면 2 초가 의도 한대로 작동하지 않을 수 1있지만 1기본값이 확실하다고 생각 하며 변경하기 위해 사소한 작업을 수행해야합니다 (에 항목을 추가해야 함 ~/Library/Preferences/.GlobalPreferences.plist).


좋아, 나는 이것을 생각해 냈다.

XCode 11 버전 11

selectParagraph:, delete:, undo:, moveRight:, yankAndSelect:
  • 클립 보드를 건드리지 않습니다
  • 여러 줄로 작동
  • 추가 된 줄을 선택하므로 다시 선택하지 않고 여러 번 사용할 수 있습니다
  • XCode 11의 고정 선택
  • 실행 취소로 더 잘 작동

Since I'm applying this change after every XCode update, I've made a script for that. Possibly it can cause some damage, but I've tried to make it relatively safe. It makes a copy of the file, and then replaces line with its copy and additional command using perl. Requires XCode to be installed at /Applications/Xcode.app

cp /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist ~/Desktop/IDETextKeyBindingSet.plist; sudo perl -pi -e 's/\<string\>selectWord:\<\/string>/'$'\<string\>selectWord:\<\/string\>\n\t\t\<key\>Duplicate Selection\<\/key\>\n\t\t\<string\>selectParagraph:, delete:, undo:, moveRight:, yankAndSelect:\<\/string>/g' /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist

Older version (I'm not sure if the new one is compatible with older versions, so I'll keep it here):

selectParagraph:, delete:, yank:, moveToBeginningOfLine:, setMark:, yank:, moveToBeginningOfLine:, moveLeft:, selectToMark:

and script for older version to avoid manual file editing:

cp /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist ~/Desktop/IDETextKeyBindingSet.plist; sudo perl -pi -e 's/\<string\>selectWord:\<\/string>/'$'\<string\>selectWord:\<\/string\>\n\t\t\<key\>Duplicate Selection\<\/key\>\n\t\t\<string\>selectParagraph:, delete:, yank:, moveToBeginningOfLine:, setMark:, yank:, moveToBeginningOfLine:, moveLeft:, selectToMark:\<\/string>/g' /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist

edit: minor fix edit2: changed to paragraph selection edit3: added version for XCode 11


Why duplicate a single line? Duplicate whole paragraph is better. My sequence:

Duplicate Current Paragraph

selectParagraph:,
delete:,
yank:,
moveToBeginningOfParagraph:,
yank:,
moveUp:,
moveToEndOfParagraph:

Delete Current Paragraph

selectParagraph:,
delete:,
moveUp:,
moveToEndOfParagraph:

Works fine in Xcode 4.6


I'm wondering why nobody has mentioned using along with the arrow keys () to both move the cursor and to select entire lines (by adding ).

I regularly copy entire lines (duplicate) by moving the cursor to the beginning of a line using + (instead of ctrl+A) and then use ++ (instead of ctrl++E) to select the whole line to the end and then copy/paste.

I've run into other threads where noone seems to use these keyboard shortcuts. They are global in OS X and I use them all the time! Much less hand-acrobatics ;)


EDIT: Sep 17, 2019 After update to Xcode 10.3 again my duplicate line key entry from the plist file was gone. I had to add it again. The key binding was still there though.

EDIT: May 28, 2019 After update to Xcode 10.2 again my duplicate line key entry from the plist file was gone. I had to add it again. The key binding was still there though.

EDIT: Dec 23, 2018 After update to Xcode 10.1 all my shortcuts broke again. But something different was that after updating the plist file for line duplication, I didn't have to define my key bindings, they were already there. Strange.

EDIT: OCT 14, 2018 Xcode 10: Somebody high up at Apple really loves copy/paste, and makes sure that with every version of Xcode update, the line duplication is removed from everyone's install. We developers have been extremely frustrated by this nonsense going on in Xcode since forever, the only IDE with no line duplication option. I just updated to Xcode 10, and as you guessed it - all my shortcut keys are removed along with my line duplication functionality. However, it is fixable like in the original answer. A slight difference this time is that you will need the following line:

<string>selectLine:, copy:, moveToBeginningOfLine:, paste:, moveToEndOfLine:</string>

EDIT: Xcode 9: I had to redo my shortcuts and line duplication and deletion, but good thing is that now you can edit IDETextKeyBindingSet.plist again. This high up Apple guy must be on vacation when they released this version.

EDIT: Xcode 8: Buggy, you can't modify the IDETextKeyBindingSet.plist file at all. Xcode resets it on start. This high up guy at Apple is really determined to make us use copy/paste instead of simple line duplication like in all other IDEs out there.

EDIT: Xcode 7.1 and still there are no shortcuts for line duplication and deletion. This is the only IDE I have ever worked with with no such shortcuts. And I can't imagine life of a developer without these two critical shortcuts.

Based on what I have read, I set up my Xcode for these shortcuts and blogged about it at: http://jixte.com/2016/03/30/line-duplicate-and-deletion-in-xcode-7-x/

Here is how it can be done:

First we need to modify a plist file that lives inside the Xcode.app bundle (needs sudo to edit)

/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist

Then look for <key>Insertions and Indentations</key> and under the <dict> tag add the following:

<key>Insert New Line Below</key>
<string>moveToEndOfLine:, insertNewline:</string>
<key>Insert New Line Above</key>
<string>moveUp:, moveToEndOfLine:, insertNewline:</string>
<key>Duplicate Current Line</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>

Then find the and these inside the section <key>Deletions</key> under the <dict> tag:

<key>Delete Current Line</key>
<string>selectLine:, delete:</string>
<string>selectLine:, delete:</string>

여기에 이미지 설명을 입력하십시오

Now Open/Restart Xcode, go to Preferences and go to the “Key Bindings” tab. Use the search bar to filter and look for the new shortcuts. Then click in front of the shortcut description to assign it a shortcut of your liking. Make sure your shortcut doesn't conflict with existing shortcuts.

여기에 이미지 설명을 입력하십시오


I would consider revising the command sequence to:

selectLine:,
copy:,
moveToEndOfLine:,
insertNewline:,
deleteToBeginningOfLine:,
paste:,
moveToBeginningOfLine:, 
deleteBackward:

The added deleteToBeginningOfLine maintains the indenting of the duplicated line.


insertLineBreak needed at least for me to make copy on new line, without it i got copy on same line


I had a big trouble to unlock .plist file on MacOS Sierra and Xcode 9, even @Tim decision didn't work for me. If you have the same problem, go to terminal and do this:

cd /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/
sudo chmod -R 777 *
nano IDETextKeyBindingSet.plist

Few other possible ways to do this are also described here.

Then in nano editor click ^W and type 'insertions' to jump to 'Insertions and Indentations' part. Just under <dict> tag paste this xml-snippet:

<key>Duplicate line</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewLine:, paste:, deleteBackward:</string>

Press control + X, then Y, then Enter to save the file in nano editor.

UPD: I came up with a better decision, which adds an additional line before duplication (useful when you want to duplicate a line which has an another line just below it):

<key>Duplicate line</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertLineBreak:, moveUp:, paste:, moveToBeginningOfLine:</string>

Here is my Delete (CTRL+D) and Duplicate (CMD+SHIFT+D) entries from my IDETextKeyBindingSet.plist. (in /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources )

I just set these up in Xcode 4.6.1 (based on answer from user570753 above and elsewhere)

    <key>Custimozed</key>
<dict>
    <key>Delete Current Line</key>
    <string>deleteToBeginningOfLine:, moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToBeginningOfLine:</string>
    <key>Duplicate Current Line</key>
    <string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, deleteToBeginningOfLine:, paste:, moveToBeginningOfLine:, deleteBackward:</string>
</dict>

XCode에서 sublime의 duplicateLineUpduplicateLineDown일치 시키려는 숭고한 텍스트 사용자는 IDETextKeyBindingSet.plist 파일에 다음을 추가 하십시오.

<key>Line Duplications</key>
<dict>
    <key>Duplicate Current Line Above</key>
    <string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:, moveUp:</string>
    <key>Duplicate Current Line Below</key>
    <string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
</dict>

다른 사람이 IDETextKeyBindingSet.plist를 편집 할 수있는 액세스가 거부 된 경우 다음을 통해 읽기 / 쓰기 권한을 부여 할 수 있습니다.

sudo chmod 777 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist

Hailei의 답변을 보완하기 위해 나에게 가장 효과적인 명령은 다음과 같습니다.

selectLine:, copy:, moveRight:, moveLeft:, insertNewline:, paste:, deleteBackward:

그의 제안 된 명령은 아래의 두 줄로 원하는 줄을 복사하는 것이 었습니다.


<key>Duplicate Lines</key>    
<string>selectLine:, copy:, moveToBeginningOfLine:, paste:</string>

중복 라인이 지원됩니다. (이것은 Xcode 9.2에서 작동합니다)

참고 URL : https://stackoverflow.com/questions/10266170/xcode-duplicate-line

반응형