Search code examples
sublimetext3

Change the length of selected text lines sublime text 3?


Is there a way to split selected long text into multiple shorter lines?

For example: from this

French President Emmanuel Macron said France will not accept text that does not mention the historic Paris accord.

"If we don't talk about the Paris agreement and if we don't get an agreement on it among the 20 members in the room, we are no longer capable of defending our climate change goals and France will not be part of this," he said on Wednesday.

France was one of the main drivers behind the Paris accord and the French parliament is now debating an energy bill that targets net zero greenhouse gas emissions by 2050.

"Negotiations on the topic of climate will be especially difficult this time," a German government official said.

to something like this

French President Emmanuel Macron said France will not accept text that does not 
mention the historic Paris accord. 

"If we don't talk about the Paris agreement and if we don't get an agreement on 
it among the 20 members in the room, we are no longer capable of defending our 
climate change goals and France will not be part of this," he said on 
Wednesday. 

France was one of the main drivers behind the Paris accord and the French 
parliament is now debating an energy bill that targets net zero greenhouse gas 
emissions by 2050. 

"Negotiations on the topic of climate will be especially difficult this time," 
a German government official said.

Solution

  • There are two ways to do something like this, depending on whether you want to leave the text alone and be able to read long lines or if you want to physically modify the file.

    Soft Wrapping

    If you just want to view the text but leave it physically the same, then what you want is Word Wrapping. You can toggle the state of View > Word Wrap to turn wrapping on and off, and the options in View > Word Wrap Column specify where the wrapping will occur. Automatic chooses the edge of the window, or you can specify a specific column for the data to wrap on.

    This is Soft Wrapping; you'll notice that the lines in the gutter do not correspond 1:1 with the actual lines because there is one physical line but several logical lines (Here the wrap setting is set to Automatic):

    Example of Soft Wrapping

    The word wrap state is controlled by the word_wrap setting in the default preferences; that determines what the default wrap state is. Changing the wrap from the menu will change it only for the file that you're currently editing, so if you want to change the state permanently, you should change that setting.

    Additionally, the wrap_width setting controls where the soft wrap happens, with 0 (the default) being the width of the window (i.e. the Automatic setting in the menu). The menu items under View > Word Wrap Column change the value of this setting to specific values, but you can set any value you like in your preferences.

    Hard Wrapping

    If you want to physically modify the text, then you want the options in the Edit > Wrap menu instead. Here you can select text to have all of it wrapped, or just put the cursor inside of a paragraph to have only that one paragraph wrapped.

    You have the option of wrapping at specific columns or at the current ruler, which you can specify in View > Ruler.

    When done in this manner, the content of the file is physically modified (Here I chose the option to wrap at column 70 and turned the soft wrapping from above off):

    Example of hard wrapping

    The position of the ruler (or rulers; you can have more than one) is controlled by the rulers setting, which by default is empty. The menu item above sets the ruler in the current file to the value shown in the menu item, but you can set the rulers setting to anything you want. As above, the defaults for the settings are in your Preferences file and the menu items only change the state for the current file, so you need to modify your preferences to set a permanent value.

    It's also worth nothing that the menu items that wrap at specific columns use the wrap_lines command with a specified width argument, so if desired you can craft a custom key binding that would wrap at any position you want.