Sublime Forum

How to copy line in Sublime without new line

#1

In Sublime when you have nothing selected and click ctrl+c you will copy whole line with the new line. How to remove that new line, so ctrl+c will copy only current line.

I’m using Sublime on Windows.

0 Likes

#4

A naive attempt:

copy_without_newline_command.py

import sublime
import sublime_plugin


class CopyWithoutNewlineCommand(sublime_plugin.TextCommand):
    def run(self, _: sublime.Edit) -> None:
        if self.view.has_non_empty_selection_region():
            self.view.run_command('copy')
            return

        sublime.set_clipboard(
            "\n".join(
                self.view.substr(self.view.line(region))
                for region in self.view.sel()
            )
        )
1 Like

#5

But how to assign it to a keyboard shortcut?

0 Likes

#6
    { "keys": ["ctrl+shift+c"], "command": "copy_without_newline" },
1 Like