Search code examples
sublimetext3sublimetextsublime-text-plugin

In Sublime Text how to copy line without end of line character


It is very useful that in ST3 you can copy a whole line with just ctrl+c, the only problem is that this command also copies the "return" or new line character, so for example when you copy a line and paste in a console it will run the command immediately. This is undesirable because I will want to first edit the command before running it. This forces me to manually highlight the line.

Is there a plugin or an easy way to cope the line where the cursor is without including the new line character?


Solution

  • You can replace the default behavior by creating a Sublime Text macro and a key bind for it on the Ctrl+C key:

    Packages/User/SelectLineNoEOL.sublime-macro

    [
        { "command": "move_to", "args": { "to": "hardbol" } },
        { "command": "move_to", "args": { "to": "eol", "extend": true } },
        { "command": "copy" },
    ]
    


    Default.sublime-keymap

        { "keys": ["ctrl+c"], "command": "run_macro_file",
            "args": {"file": "res://Packages/User/SelectLineNoEOL.sublime-macro"},
            "context":
            [
                { 
                    "key": "selection_empty", "operator": "equal",
                    "operand": true, "match_all": false,
                },
            ],
        },
    

    I think I had saw another thread with a plugin which does this, but I could not find it.

    Related threads:

    1. forum#14576 How to disable selecting newline on triple click?
    2. forum#14933 [ST3]Copy blank line using yy;p (Vi), paste one extra line