1
使用Sublime Text,我在左邊的一列中有文本塊,我想選擇性地將一些行一個單獨的文件在右邊。Sublime Text - 如何創建一個鍵盤快捷方式將文本從一個打開的文件移動到另一個打開的文件
是否有一個現有的鍵盤快捷鍵來做到這一點,如果不是,我會怎麼把它放在一起。具體的步驟是
1. Cut selection
2. Change to other column
3. Paste selection
使用Sublime Text,我在左邊的一列中有文本塊,我想選擇性地將一些行一個單獨的文件在右邊。Sublime Text - 如何創建一個鍵盤快捷方式將文本從一個打開的文件移動到另一個打開的文件
是否有一個現有的鍵盤快捷鍵來做到這一點,如果不是,我會怎麼把它放在一起。具體的步驟是
1. Cut selection
2. Change to other column
3. Paste selection
我寫了一個簡單的插件,以滿足你的問題的要求,並具有一些新的特點:
copy
& cut
命令(從活動文檔不活動的文件,適用於要麼查看)將以下代碼複製到:
Packages/MoveTextToInactiveDocument/MoveTextToInactiveDocument.py
import sublime, sublime_plugin
LINE_BREAK = "\n"
class MoveTextToInactiveDocumentCommand(sublime_plugin.TextCommand):
def run(self, edit, MODE = "copy"):
view = self.view
window = view.window()
#■■■ Verify Window Groups ■■■#
windowGroup_Count = window.num_groups()
if windowGroup_Count != 2:
return
#■■■ Set Active & Inactive Documents ■■■#
activeDocument_Group = window.active_group()
if activeDocument_Group == 0:
activeDocument = window.active_view_in_group(0)
inactiveDocument = window.active_view_in_group(1)
elif activeDocument_Group == 1:
activeDocument = window.active_view_in_group(1)
inactiveDocument = window.active_view_in_group(0)
#■■■ Verify Selection ■■■#
selections = activeDocument.sel()
if len(selections) == 0:
return
#■■■ Move Text From Active Document To Inactive Document ■■■#
first_InsertionPoint = inactiveDocument.size()
for region in selections:
regionText = activeDocument.substr(region) + LINE_BREAK
insertionPoint = inactiveDocument.size()
inactiveDocument.insert(edit, insertionPoint, regionText)
if MODE.lower() == "cut":
activeDocument.erase(edit, region)
#■■■ Select & Scroll To Inserted Text ■■■#
inactiveDocument_End = inactiveDocument.size()
insertedText_Region = sublime.Region(first_InsertionPoint, inactiveDocument_End)
inactiveDocument.selection.clear()
inactiveDocument.selection.add(insertedText_Region)
inactiveDocument.show(inactiveDocument.size())
window.focus_view(activeDocument)
運行打開用戶sublime-keymap
文件來自0的。
添加以下key-bindings
。
{
"keys": [ "ctrl+super+c" ],
"command": "move_text_to_inactive_document",
"args": { "MODE": "Copy" }
},
{
"keys": [ "ctrl+super+x" ],
"command": "move_text_to_inactive_document",
"args": { "MODE": "Cut" }
},
您現在可以使用:
這是偉大的@ Enteleform。謝謝。代碼非常容易理解,因此非常有用。 –