使用Sublime Text,我在左边的列中有文本块,我想选择性地将一些行移到右边的单独文件中。
是否有现成的键盘快捷键可以执行此操作,如果不是,我将如何将其放在一起。步骤将是
1. Cut selection
2. Change to other column
3. Paste selection
答案 0 :(得分:1)
我写了一个简单的插件,可以满足您的问题的要求,还有一些额外的功能:
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
运行Preferences: Key Bindings - User
,打开您的用户command palette
文件。
添加以下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" }
},
您现在可以使用: