@@ -1160,6 +1160,45 @@ mod cmd {
11601160 }
11611161 }
11621162
1163+ /// Sets or reports the current document's line ending setting.
1164+ fn set_line_ending(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1165+ use LineEnding::*;
1166+
1167+ // If no argument, report current line ending setting.
1168+ if args.is_empty() {
1169+ let line_ending = current!(editor).1.line_ending;
1170+ editor.set_status(match line_ending {
1171+ Crlf => "crlf".into(),
1172+ LF => "line feed".into(),
1173+ FF => "form feed".into(),
1174+ CR => "carriage return".into(),
1175+ Nel => "next line".into(),
1176+
1177+ // These should never be a document's default line ending.
1178+ VT | LS | PS => "error".into(),
1179+ });
1180+ return;
1181+ }
1182+
1183+ // Attempt to parse argument as a line ending.
1184+ let line_ending = match args.get(0) {
1185+ // We check for CR first because it shares a common prefix with CRLF.
1186+ Some(arg) if "cr".starts_with(&arg.to_lowercase()) => Some(CR),
1187+ Some(arg) if "crlf".starts_with(&arg.to_lowercase()) => Some(Crlf),
1188+ Some(arg) if "lf".starts_with(&arg.to_lowercase()) => Some(LF),
1189+ Some(arg) if "ff".starts_with(&arg.to_lowercase()) => Some(FF),
1190+ Some(arg) if "nel".starts_with(&arg.to_lowercase()) => Some(Nel),
1191+ _ => None,
1192+ };
1193+
1194+ if let Some(le) = line_ending {
1195+ doc_mut!(editor).line_ending = le;
1196+ } else {
1197+ // Invalid argument.
1198+ editor.set_error(format!("invalid line ending '{}'", args[0],));
1199+ }
1200+ }
1201+
11631202 fn earlier(editor: &mut Editor, args: &[&str], event: PromptEvent) {
11641203 let uk = match args.join(" ").parse::<helix_core::history::UndoKind>() {
11651204 Ok(uk) => uk,
@@ -1392,6 +1431,13 @@ mod cmd {
13921431 fun: set_indent_style,
13931432 completer: None,
13941433 },
1434+ TypableCommand {
1435+ name: "line-ending",
1436+ alias: None,
1437+ doc: "Set the document's default line ending. Options: crlf, lf, cr, ff, nel.",
1438+ fun: set_line_ending,
1439+ completer: None,
1440+ },
13951441 TypableCommand {
13961442 name: "earlier",
13971443 alias: Some("ear"),