From af2ec9d540e9e0ac736113435cd76a353d7e76aa Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Mon, 4 Mar 2024 22:20:02 +0100 Subject: [PATCH] Make default fileformat value suited to the OS (#3141) Set fileformat by default to `dos` on Windows. --- internal/config/settings.go | 10 +++++++++- runtime/help/options.md | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/config/settings.go b/internal/config/settings.go index 72e998f1..05a9f8a4 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "reflect" + "runtime" "strconv" "strings" @@ -284,7 +285,7 @@ var defaultCommonSettings = map[string]interface{}{ "encoding": "utf-8", "eofnewline": true, "fastdirty": false, - "fileformat": "unix", + "fileformat": defaultFileFormat(), "filetype": "unknown", "hlsearch": false, "incsearch": true, @@ -319,6 +320,13 @@ var defaultCommonSettings = map[string]interface{}{ "wordwrap": false, } +func defaultFileFormat() string { + if runtime.GOOS == "windows" { + return "dos" + } + return "unix" +} + func GetInfoBarOffset() int { offset := 0 if GetGlobalOption("infobar").(bool) { diff --git a/runtime/help/options.md b/runtime/help/options.md index 3170dc4c..75e877e8 100644 --- a/runtime/help/options.md +++ b/runtime/help/options.md @@ -157,7 +157,7 @@ Here are the available options: an effect if the file is empty/newly created, because otherwise the fileformat will be automatically detected from the existing line endings. - default value: `unix` + default value: `unix` on Unix systems, `dos` on Windows * `filetype`: sets the filetype for the current buffer. Set this option to `off` to completely disable filetype detection.