Search code examples
sublimetext3sublimetexttext-editorline-breaks

Sublime Text break line at cursor


I am using Sublime Text 3 with Vintage enabled. I have it set up so I can join lines using shift+j in command mode. I want to use shift+k to break a line at the cursor. Is this possible?

For example, if I have an array like the following:

array('item1', 'item2', 'item3');

I want to be able to move the cursor to each starting single quote, hit shift+k and have it move to another line. If I hit shift+k at the first quote, I would get this:

array(

    'item1', 'item2', 'item3');

Solution

  • This is possible in Vintage by setting a key binding such as the following in your user key bindings:

    { "keys": ["K"], "command": "insert", "args": {"characters": "\n"},
        "context":
        [
            { "key": "setting.command_mode"},
        ]
    },
    

    Note however that this will mask the following default key binding in Vintage, which may or may not be a problem:

    { "keys": ["k"], "command": "set_motion", "args": {
        "motion": "move",
        "motion_args": {"by": "stops", "line_begin": true, "forward": false, "extend": true },
        "linewise": true },
        "context":
        [
            {"key": "setting.command_mode"},
            {"key": "vi_motion_mode", "operand": "line"}
        ]
    },