Fix removal of extra white spaces

This commit is contained in:
Jeremy Gardais 2023-08-11 09:52:36 +02:00
parent 7e69b65e76
commit 3f25b72edb
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 24 additions and 4 deletions

28
vimrc
View File

@ -124,11 +124,12 @@ nmap <leader>x :w<cr>:!./"%"<cr>
" Édition rapide de vimrc avec <leader>+e " Édition rapide de vimrc avec <leader>+e
map <leader>e :e! ~/.vim/vimrc<cr> map <leader>e :e! ~/.vim/vimrc<cr>
""" Splits {{{ " Splits {{{
" Open new split on the bottom part " Open new split on the bottom part
set splitbelow set splitbelow
" Open new split on the right part " Open new split on the right part
set splitright set splitright
" }}}
" FZF function to list all files on the system {{{ " FZF function to list all files on the system {{{
function! FzfFiles() function! FzfFiles()
@ -1011,15 +1012,34 @@ au BufWritePost * call ModeChange()
set list set list
"set listchars=eol:⏎,nbsp:⎵,tab:▸·,extends:>,precedes:<,trail:␠ "set listchars=eol:⏎,nbsp:⎵,tab:▸·,extends:>,precedes:<,trail:␠
set listchars=nbsp:⎵,tab:▸·,extends:>,precedes:<,trail:␠ set listchars=nbsp:⎵,tab:▸·,extends:>,precedes:<,trail:␠
" Afficher les espaces superflus en gris clair
" Manage ExtraWhiteSpace {{{
" Display ExtraWhiteSpace (spaces at the End Of the Line) in gray
highlight ExtraWhitespace ctermbg=darkgray guibg=lightred highlight ExtraWhitespace ctermbg=darkgray guibg=lightred
match ExtraWhitespace /\s\+$/ match ExtraWhitespace /\s\+$/
" Auto-remove extra whitespaces before writing the file " Function to clean it
autocmd BufWritePre * :%s/\s\+$//e function! CleanTrailingWhitespace()
" https://stackoverflow.com/questions/6496778/vim-run-autocmd-on-all-filetypes-except
" Specific sed command for mail filetype
if &ft =~ 'mail'
" Want to keep email's signature (begin with "--" + one extra whitespace).
" https://stackoverflow.com/questions/45294980/in-sed-how-to-do-a-pattern-substitution-only-when-another-pattern-doesnt-exist
:g!/^--/s/\s\+$//g
return
endif
" Default sed command on all other filetypes
%s/\s\+$//e
endfunction
" Call function before saving
autocmd BufWritePre * call CleanTrailingWhitespace()
" }}}
" Auto-remove extra ⏎ before writing the file " Auto-remove extra ⏎ before writing the file
autocmd BufWritePre * :%s/⏎\+$//e autocmd BufWritePre * :%s/⏎\+$//e
" Search for 2 whitespaces and highlight it (red and underline) " Search for 2 whitespaces and highlight it (red and underline)
set hls set hls
let g:HLSpace = 1 let g:HLSpace = 1