Since there is already a binding for "m+":
Vintage/Default.sublime-keymap
:
{ "keys": ["m", "<character>"], "command": "vi_set_bookmark",
"context": [{"key": "setting.command_mode"}]
},
You might have trouble getting the keymap you want. But try this:
{ "keys": [":", "m"], "command": "move_text_to_line",
"context": [{"key": "setting.command_mode"}]
},
Typing ":m" should activate this binding in command mode.
Now, we need a MoveTextToLine command. In your case, it sounds like you'd prefer to have this command work on the current line, not the selection, which is how MoveText works.
This is an easy command, so I'll just write it.
-
get the region for the current line.
cursor = self.view.sel()[0].b # "b" point of the first selection == the cursor line = self.view.full_line(cursor) # full_line includes the newline
-
get the destination
self.view.window().show_input_panel('Move to:', '', move_line, None, None)
-
move the line there
def move_line(dest_row): dest_row -= 1 # text_point is zero-indexed, not 1 dest_point = self.view.text_point(dest_row, 0) # 0th col of dest_row
content = self.view.substr(line) if content[-1] != "\n": content += "\n" # make sure there is a new line e = self.view.begin_edit('move_text') self.view.replace(e, line, '') self.insert(e, dest_point, content) self.view.end_edit(e)
-
Okay, all together, see the
move_text_to_line.py
file. I've added support for selections (if the line is selected, instead of just an empty cursor), and some error handling.
Enjoy!