6

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.

9

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.

  • Excellent, 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. – orokusaki May 3 '12 at 21:49
3

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

1

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.

0

With Komodo[edit], one can control replacements of CR manually using regular expressions replacement tool. Same goes for most popular editors. This used to work great with np++.
Here is the way to go with Komodo:

  1. Fill in Find input with \r
    enter image description here
  2. Then make sure to switch on BOTH following options
    "Treat the pattern as a regular expression" (No need explanation)
    "Use Multiple Lines" (Search will treat file content as a whole and not line by line. As a consequence pattern will match any characters until it fails, including CR, LF, etc. )

    enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.