Sublime Forum

UNIX line endings for *.sh files?

#1

I am creating and editing UNIX shell scripts (with extension .sh) on Windows. I’d like these to automatically have UNIX line endings. It’s a pain to have to set them manually, and I often forget. Is there a way to do this?

I realize this topic has already been discussed on this forum (see link below) but I find the answer so terse that I can’t figure out what I’m supposed to do. Can someone please spell this out in detail, as in an ST for Dummies book.

0 Likes

#2

The instructions in the post that you linked are pretty spot on, but:

  1. Open a file of the type you want to modify settings for

  2. Select Preferences > Settings - Syntax Specific from the menu

  3. Search in the left hand pane of the new window for the setting that you want to modify (here it’s default_line_ending)

    // Determines what character(s) are used to terminate each line in new files.
    // Valid values are 'system' (whatever the OS uses), 'windows' (CRLF) and
    // 'unix' (LF only).
    "default_line_ending": "system",
    
  4. Copy the setting from the defaults to the settings file on the right and alter the value (here you want the value unix

  5. Save the settings file and close the window

Now the settings that you put there will apply to any file of the type that you selected automatically.

This video covers settings and how they work in Sublime, which may also be helpful.

1 Like

#3

Thanks for the very clear explanation. And it works!

1 Like

#4

\n should be ST’s default line ending for shellscript syntax imo.

Tip (maybe): I use unix as the default line ending (rather than system). And use windows in syntax-specific settings for those which are most likely for Windows such as batch and powershell.

0 Likes