How can I replace all \r\n with \n using Komodo Edit
Solution 1
There is actually a built-in feature for this in Komodo, but it's hard to find.
Right-click the Edit
tab select Current File Settings
. Under File Settings
, change "Line Endings" to UNIX (\n) and de-select "Preserve existing line endings".
This is fine for individual files, but it would be a bit of a hassle if you were trying to do several files as a batch. For that, you could wrap some of swatso33's suggestions into a saved command using interpolation shortcuts.
UPDATE (2014-10-13): There is now an option: Clean Line Endings
under the Code
tab.
Solution 2
You can do this with either perl or sed using:
perl -pe 's/\r?\n|\r/\r\n/g' inputfile > outputfile # Convert to DOS.
perl -pe 's/\r?\n|\r/\n/g' inputfile > outputfile # Convert to UNIX.
sed -e 's/$/\r/' inputfile > outputfile # UNIX to DOS (adding CRs on Linux based OS that use GNU extensions).
sed -e 's/\r$//' inputfile > outputfile # DOS to UNIX (removing CRs on Linux based OS that use GNU extensions).
perl -pe 's/\r?\n|\r/\r/g' inputfile > outputfile # Convert to old Mac.
Code snippet is from http://en.wikipedia.org/wiki/Newline#Conversion_utilities
Solution 3
At http://bugs.activestate.com/show_bug.cgi?id=93976 I give a macro that changes the line-end setting and the actual line-endings when a file that is under Git SCC is opened in Komodo.
You can also modify that macro to quickly update all loaded files.
Related videos on Youtube
orokusaki
I'm Michael Angeletti. I am a Python / Django developer, specializing in SaaS applications.
Updated on September 18, 2022Comments
-
orokusaki over 1 year
Somehow, some 40 files (mostly Python modules) in my project have
\r\n
(Windows style) as line endings. I'd like to change them to\n
(Unix style) line endings, but Komodo Edit doesn't appear to provide a way change existing files' line endings, and a simple regexp find and replace using Komodo doesn't work either. -
orokusaki about 12 yearsExcellent, thanks. I ended up spendin 20 minutes last night changing them by doing open file -> copy contents -> command w -> close and delete file -> command shift t (which prompts to recreate the file) -> paste contents -> save. I got each one down to about 8 seconds by the end lol, but wasted time early on doing extra steps.