Sublime Forum

Copy nothing?

#1

I’ve noticed that you can copy (Ctrl+c) nothing! this overwrites the buffer, seems a bit silly to me, and would hopefully be simple to code a check?

1 Like

Do not 'copy' when command+c is pressed but selection empty
#2

It seems that when nothing is selected, it will select whatever is on the current line. If the line is blank, it will copy the “new line” character.

0 Likes

#3

Yeah, that always annoyed me, thoughly mainly the ctrl+x for deleting empty lines. No point in putting the empty line on the clipboard is there.

All paths referenced are rooted at the folder opened by the Preferences->Browse Packages command.

Add this to User/Default ($platform).sublime-keymap (adjusting keys for different platforms etc):

{
    "command": "run_macro_file", 
    "args": {"file": "Packages/User/delete-empty-line.sublime-macro"}
    "context": 
      {
        "key": "preceding_text",
        "operand": "\\S",
        "operator": "not_regex_contains"
      },
      {
        "key": "following_text",
        "operand": "\\S",
        "operator": "not_regex_contains"
      },
      {
        "key": "selection_empty",
        "match_all": true,
        "operand": true,
        "operator": "equal"
      }
    ],
    "keys": 
      "ctrl+x"
    ]
},
{
    "command": "noop", 
    "context": 
      {
        "key": "preceding_text",
        "operand": "\\S",
        "operator": "not_regex_contains"
      },
      {
        "key": "following_text",
        "operand": "\\S",
        "operator": "not_regex_contains"
      },
      {
        "key": "selection_empty",
        "match_all": true,
        "operand": true,
        "operator": "equal"
      }
    ],
    "keys": 
      "ctrl+c"
    ]
}

Add this to Packages/User/delete-empty-line.sublime-macro:


    {
      "args": {
        "to": "line"
      },
      "command": "expand_selection"
    },
    {
      "args": {},
      "command": "left_delete"
    }
]

I haven’t really tested the above, as it’s modified from what I use myself but it should point you in the right direction.

0 Likes

#4

Thanks so much for providing this! I was hoping to find exactly what you shared and lo, there it was and more (I hadn’t thought to make Ctrl+X delete the line without erasing clipboard).

There were a couple missing brackets, etc. so I’m reposting your code. I can confirm it works and on ST3 in 2018 :slight_smile:

Place these in your User Keybindings file, comma-delimited as with all other keybindings. Add the macro file as described above if you use the Ctrl+X override, too.

Add this (and the macro file) for overriding Ctrl+X CUT behavior when line is blank

ST3 will instead delete the line and preserve contents of clipboard:

{
    "command": "run_macro_file",
    "args": {"file": "Packages/User/delete-empty-line.sublime-macro"},
    "context":
    [
      {
        "key": "preceding_text",
        "operand": "\\S",
        "operator": "not_regex_contains"
      },
      {
        "key": "following_text",
        "operand": "\\S",
        "operator": "not_regex_contains"
      },
      {
        "key": "selection_empty",
        "match_all": true,
        "operand": true,
        "operator": "equal"
      }
    ],
    "keys": ["ctrl+x"]
}

Add this (no macro file needed) for overriding Ctrl+C COPY behavior when line is blank

ST3 will instead ignore you so you can try again to find Ctrl+V, heh:

{
    "command": "noop",
    "context":
    [
        {
            "key": "preceding_text",
            "operand": "\\S",
            "operator": "not_regex_contains"
        },
        {
            "key": "following_text",
            "operand": "\\S",
            "operator": "not_regex_contains"
        },
        {
            "key": "selection_empty",
            "match_all": true,
            "operand": true,
            "operator": "equal"
        }
    ],
    "keys": ["ctrl+c"]
}

Macro file contents:

[
    {
        "args": {
        "to": "line"
    },
        "command": "expand_selection"
    },
    {
        "args": {},
        "command": "left_delete"
    }
]
0 Likes