Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a Sublime Text shortcut for 'Edit - Wrap - Wrap at XX characters'

I need to set a shortcut for the Edit - Wrap - Wrap at XX characters command in Sublime Text 3.

I'm aware of the AutoWrap package, but that works as you write splitting long lines into new ones.

The article Adding Word Wrap Toggle Shortcut Key in Sublime Text 3 explains how to add a shortcut but not to break long lines, it just wraps them.

I need to wrap at 80 chars, but it'd be great if I could set the XX number of characters.

like image 935
Gabriel Avatar asked Sep 02 '25 05:09

Gabriel


1 Answers

The command that the menu items you reference above use to perform the wrap is the wrap_lines command. It takes an argument width that specifies at what column the wrap should occur, so you can provide any width you want in your binding, or have multiple bindings to have multiple pre-set wrap amounts.

For example:

{
    "keys": ["super+w"],
    "command": "wrap_lines",
    "args": {
        "width": 80
    },        
},  
{
    "keys": ["shift+super+w"],
    "command": "wrap_lines",
    "args": {
        "width": 40
    },        
},   

The width argument to the command is optional; if you don't provide it, Sublime chooses a default:

  1. The column set in the View > Word Wrap Column menu
  2. If the wrap column is set to Automatic, the ruler from the View > Ruler menu
  3. If the ruler is set to None, then the wrap happens at column 78.

Note also that the value of the wrap column can be adjusted infinitely by altering the wrap_width setting, and the list of rulers can be adjusted to whatever you want by using the rulers setting. The related menu items are just modifying the value of the setting in the current view.

As a note on rulers, there can be more than one of them listed; if that is the case, the first one in the list would be used as the wrap point in #2 above.

like image 73
OdatNurd Avatar answered Sep 05 '25 00:09

OdatNurd