Text file line endings: LF, CRLF, and CR
Line endings are control characters that separate text lines. They are usually invisible in an editor, but different conventions affect comparisons, version-control diffs, and scripts.
Common line-ending sequences
- LF (
U+000A,\n): line feed, used by Unix-like systems and most modern web formats. - CRLF (
U+000D U+000A,\r\n): carriage return followed by line feed, common in Windows text files. - CR (
U+000D,\r): carriage return alone, found in some older text files and uncommon in current workflows.
These are byte or code-point sequences, not visible punctuation in the rendered text. UTF-8 encodes LF and CR as single bytes, but other file encodings have different byte representations.
Mixed endings and final newlines
A file may contain more than one kind of separator, often after being edited by tools with different defaults. A final line terminator is separate from the choice of separator between lines: a file can end with a newline or omit it. Some line-counting commands count terminator characters, so the last unterminated line may not be included in a newline count.
TinyDevTools behavior
The five text tools split on CRLF or LF and join output lines with LF. They do not split on lone CR, preserve a source file's encoding, or provide line-ending selection. This is suitable for quick pasted-text operations, not a replacement for a file converter.
Choosing a repository convention
Projects can document line-ending expectations and use a repository-level .gitattributes rule to normalize text files. Choose rules based on the consumers of those files; shell scripts, generated artifacts, and Windows-specific formats can have different requirements. Review the resulting diff after changing repository settings.
For practical normalization tradeoffs, see how the line tools handle pasted input.
Advertisements