@@ -352,8 +352,26 @@ fn set_line_ending(
352352 arg if arg.starts_with("nel") => Nel,
353353 _ => bail!("invalid line ending"),
354354 };
355+ let (view, doc) = current!(cx.editor);
356+ doc.line_ending = line_ending;
357+
358+ let mut pos = 0;
359+ let transaction = Transaction::change(
360+ doc.text(),
361+ doc.text().lines().filter_map(|line| {
362+ pos += line.len_chars();
363+ match helix_core::line_ending::get_line_ending(&line) {
364+ Some(ending) if ending != line_ending => {
365+ let start = pos - ending.len_chars();
366+ let end = pos;
367+ Some((start, end, Some(line_ending.as_str().into())))
368+ }
369+ _ => None,
370+ }
371+ }),
372+ );
373+ doc.apply(&transaction, view.id);
355374
356− doc_mut!(cx.editor).line_ending = line_ending;
357375 Ok(())
358376}
359377
@@ -1193,6 +1211,9 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
11931211 TypableCommand {
11941212 name: "line-ending",
11951213 aliases: &[],
1214+ #[cfg(not(feature = "unicode-lines"))]
1215+ doc: "Set the document's default line ending. Options: crlf, lf.",
1216+ #[cfg(feature = "unicode-lines")]
11961217 doc: "Set the document's default line ending. Options: crlf, lf, cr, ff, nel.",
11971218 fun: set_line_ending,
11981219 completer: None,