Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure Visual Studio to use UNIX line endings

We would like to use Visual Studio 2005 to work on a local copy of an SVN repository. This local copy has been checked out by Mac OS X (and updates and commits will only be made under Mac OS X, so no problem there), and as a consequence the line endings are UNIX-style.

We fear that Visual Studio will introduce Windows-style line endings. Is it possible to force Visual Studio to use UNIX line endings?

like image 738
moala Avatar asked Sep 27 '10 09:09

moala


People also ask

How do you change line endings in Visual Studio code to Unix?

VS Code => Settings => Files: EoLAnd choose “\n” as EoL character if you would like your files to have Unix Style line endings and choose “\r\n” if you would like your files to have Windows Style line endings. VS Code — Eol Settings for Files. That settings applies to all new files that you create.

How do I change the EoL for all files from CRLF to LF in Visual Studio code?

The Quick FixAt the bottom right of the screen in VS Code there is a little button that says “LF” or “CRLF”: Click that button and change it to your preference. Voila, the file you are editing now has the correct line breaks.

How do I view line endings in Visual Studio?

Navigate to the Visual Studio Code settings tab (e.g., by Ctrl + , (comma)) Search for end of line in the search bar. Set the desired value in the Files: Eol dropdown menu.

Can Windows handle Unix line endings?

So happy for you, Microsoft, \r\n Windows Notepad users, rejoice! Microsoft's text editing app, which has been shipping with Windows since version 1.0 in 1985, has finally been taught how to handle line endings in text files created on Linux, Unix, Mac OS, and macOS devices.


2 Answers

Warning: This solution no longer works for Visual Studio 2017 and later. Instead, both of the answers by jcox and Munther Jaber are needed. I have combined them into one answer.

As OP states "File > Advanced Save Options", select Unix Line Endings.

This will only affect new files that are created. Fixing any that were previously created can be done file-by-file or you can search for tools that will fix on-bulk.

like image 166
Zero Avatar answered Oct 07 '22 15:10

Zero


Here are some options available for Visual Studio Community 2017

  1. "File > Advanced Save Options" has been removed by microsoft due to "uncommon use". Whatever that means. https://developercommunity.visualstudio.com/content/problem/8290/file-advanced-save-options-option-is-missed.html You can add it back by going to "Tools>Customize", then "Commands" tab, select the drop down next to "Menu Bar" select "File" then "Add Command">File>Advanced Save Options..". You can then reorder it in the file menu by using "move down".

I don't know if you will have to then set the advanced save options for each and every file, but it might prevent the issue I was having where my Visual Studio kept adding CL RF line endings into my files that were uniformly LF.

  1. But I took it one step further and I added an extension called "Line Endings Unifier" by going to "Tools>Extensions and Updates>Online" and then searching for "line endings" in the search bar to the right. I will use this to automatically force all of my scripts to save with uniform line endings of my choice, but you can do more with it. https://marketplace.visualstudio.com/items?itemName=JakubBielawa.LineEndingsUnifier

  2. strip'em is another solution that does something similar to Line Endings Unifier. http://www.grebulon.com/software/stripem.php

I am not sure how they differ or the advantages/disadvantages of either. I'm mainly using Line Endings Unifier just because it was in the Visual Studio Marketplace. I think I've used all of these methods in the past, but my memory is fuzzy.

like image 35
FragmentalStew Avatar answered Oct 07 '22 17:10

FragmentalStew