From 28c88ca5f1cbf0660b053d97f6289b00aa28a920 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Thu, 16 Mar 2023 16:26:18 -0400 Subject: [PATCH] Stop git from changing line endings on Windows and add support for editorconfig in vim --- .editorconfig | 21 +++++++++++++++++++++ .gitattributes | 5 +++++ linux/gitconfig.platform | 15 ++++++++++++--- vimrc | 6 ++++++ windows/gitconfig.platform | 18 +++++++++++++++--- 5 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitattributes diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..dd4f1c7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles # between different editors and IDEs +# editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 4 + +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.bat] +end_of_line = crlf + +[*.tsv] +indent_style = tab + diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..19aa561 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# All text files will have LF line endings, except batch files. +* text=auto + +# Preserve crlf in batch files when checking in. +*.bat text eol=crlf diff --git a/linux/gitconfig.platform b/linux/gitconfig.platform index 7de3a8c..7049ef1 100644 --- a/linux/gitconfig.platform +++ b/linux/gitconfig.platform @@ -1,5 +1,14 @@ [code] - editor = vim + editor = vim [core] - # Don't change LF line endings and if a CRLF is found then change it to LF on a commit. - autocrlf = input + # Don't change any line endings. That means if a file has CRLF line endings + # the carriage return will stay. I'm only worknig with LF line endings on + # Windows now except for .bat files which are forced to have CRLF via + # per-project editorconfig and gitattribute files. I want those files to + # still have CRLFs when modified on Linux. + # + # I used these posts for reference: + # https://markentier.tech/posts/2021/10/autocrlf-true-considered-harmful/ + # https://troyready.com/blog/git-windows-dont-convert-line-endings.html + # + autocrlf = false diff --git a/vimrc b/vimrc index 79526ae..980eb0b 100644 --- a/vimrc +++ b/vimrc @@ -213,6 +213,7 @@ Plug 'vim-scripts/AnsiEsc.vim' " Ansi escape sequences concealed, but hig Plug 'sir-pinecone/errormarker.vim' " Build error highlighting (requires skywind3000/asyncrun.vim). Plug 'skywind3000/asyncrun.vim' " Async commands. Plug 'nelstrom/vim-qargs' " For the GlobalReplaceIt function (i.e. search and replace). +Plug 'editorconfig/editorconfig-vim' " Adds support for .editorconfig files. if IsWindows() Plug 'suxpert/vimcaps' " Disable capslock (useful if the OS isn't configured to do so). @@ -722,6 +723,11 @@ inoremap let g:localvimrc_sandbox = 0 let g:localvimrc_ask = 0 +"################################################################################## +" EDITOR CONFIG +"################################################################################## +let g:EditorConfig_exclude_patterns = ['fugitive://.*'] + "################################################################################## " LION (TEXT ALIGNMENT) "################################################################################## diff --git a/windows/gitconfig.platform b/windows/gitconfig.platform index ce7e101..77a04dc 100644 --- a/windows/gitconfig.platform +++ b/windows/gitconfig.platform @@ -1,5 +1,17 @@ [code] - editor = /usr/bin/vim + editor = /usr/bin/vim [core] - # Convert unix LF to Windows CRLF when checking out and vice-versa when adding files to the index. - autocrlf = true + # I used to have this set to true, which would result in checked out files + # being converted to CRLF line endings and commits converting to LF. I'm + # tired of this conversion shit though so I'm turning it off and will be + # enforcing LF line endings via a combination of editorconfig and + # gitattribute files on a per-project basis. This should make sure that + # anyone contributing to my projects will be committing LF line endings. + # The only exception is that the gitattributes files will commit batch + # files with CRLF to avoid Windows glitches. + # + # I used these posts for reference: + # https://markentier.tech/posts/2021/10/autocrlf-true-considered-harmful/ + # https://troyready.com/blog/git-windows-dont-convert-line-endings.html + # + autocrlf = false