Set line endings for all tabs and all open files

ahnbizcad picture ahnbizcad · Jan 18, 2014 · Viewed 28k times · Source

Some of my files/tabs somehow got to be Unix line endings, when I want Windows line endings. I can go to view > line endings > windows, but that applies it only for the current file/tab opened. I don't want to have to do it for every file (which I did). But even if I do this, when I open other files, sometimes they are set in Unix. Is there a single setting that can apply it for all files, whether they are opened or unopened?

If I go to preferences > Settings - default > and go to the default_line_endings setting, its value is set to 'system'. I know i COULD override this in my 'Settings - User' setting, but I didn't have to do this before the line endings somehow got all messed up. Is there another way?

Also, If i reinstall sublimetext, would this fix it, or are the line endings somehow dependent on the files themselves? I imagine it would be sublime text that decides which line endings to use, perhaps based on what line endings are in the file. But I don't know this for sure. Plus, all my line endings used to be the windows's CRLF, not Unix's LF.

Controlling the line endings in sublime text is currently kind of a pain, since it has no en masse way to view or set, current files, nor an en masse way to set it for future files.

Any knowledge would be appreciated.

Answer

trejder picture trejder · Sep 26, 2014

The Line​Endings plugin / package is small, but works like a charm Visit it's GitHub repository to get a few details, because on its Package Control page there is no description.

It not only works, but also gives you an additional functionality -- you can change not only line endings, but also indentation method of all open files in one step.

After installation:

  1. Open all files, in which you want to convert / change line endings and/or indentation method.

  2. Press Ctrl+Shift+P, to bring Command Pallete and start typing lin to locate Line Ending to all views: Windows (for example).

  3. Select it, hit Enter, and... you're done!

  4. Repeat step 2, but type spaces to locate Indentation: Convert to all views to Spaces or tabs to locate Indentation: Convert to all views to Tabs to change indentation method of all open files.

Note, that either this plugin has a bug or Sublime Text 3 gets sometimes a bit wako. Some searches did not reveal above mentioned commands. And I had to close and reopen Command Palette and type sequence again. Especially, if you have any kind of linter installed in ST3, its command may interfere with Line​Endings's commands, as you type lin.