For some reason, when I open files from a unix server on my windows machine, they occasionally have Macintosh EOL conversion, and when I edit/save them again they don't work properly on the unix server. I only use notepad ++ to edit files from this unix server, so is there a way to create a macro that automatically converts EOL to Unix format whenever I open a file?
That functionality is already built into Notepad++. From the "Edit" menu, select "EOL Conversion" -> "UNIX/OSX Format".
screenshot of the option for even quicker finding (or different language versions)
You can also set the default EOL in notepad++ via "Settings" -> "Preferences" -> "New Document/Default Directory" then select "Unix/OSX" under the Format box.
In Notepad++, use replace all with regular expression. This has advantage over conversion command in menu that you can operate on entire folder w/o having to open each file or drag n drop (on several hundred files it will noticeably become slower) plus you can also set filename wildcard filter.
(\r?\n)|(\r\n?)
to
\n
This will match every possible line ending pattern (single \r, \n or \r\n) back to \n.
To operate on multiple files, either:
- Use "Replace All in all opened document" in "Replace" tab. You will have to drag and drop all files into Notepad++ first. It's good that you will have control over which file to operate on but can be slow if there several hundreds or thousands files.
- "Replace in files" in "Find in files" tab, by file filter of you choice, e.g., *.cpp *.cs under one specified directory.
I open files "directly" from WinSCP which opens the files in Notepad++ I had a php files on my linux server which always opened in Mac format no matter what I did :-(
If I downloaded the file and then opened it from local (windows) it was open as Dos/Windows....hmmm
The solution was to EOL-convert the local file to "UNIX/OSX Format", save it and then upload it.
Now when I open the file directly from the server it's open as "Dos/Windows" :-)
来源:https://stackoverflow.com/questions/16239551/eol-conversion-in-notepad