vim: whitespaces

This commit is contained in:
Michael Grote 2023-08-29 08:32:53 +02:00
parent 942f59fec1
commit bc9e269bd0

22
.vimrc
View file

@ -236,25 +236,33 @@ nnoremap <Leader>z :set nonumber! norelativenumber!<CR>
: autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif
:augroup END
function! Whitespaces()
" einzelne Aufräumfunktionen, bei F9 werden alle gecalled
" trailing whitespaces werden automatisch beim speichern entfernt
function! Whitespaces_trailing()
" Remove trailing whitespace
%s/\s\+$//e
endfunction
function! Whitespaces_consecutive()
" Replace consecutive spaces between words with a single space (only for .md files)
if &filetype == "markdown"
%s/\(\w\)\s\+\(\w\)/\1 \2/g
endif
endfunction
function! Whitespaces_lines()
" Run silent command to remove multiple consecutive empty lines (only for .md files)
if &filetype == "markdown"
silent %!cat -s
endif
endfunction
function! Whitespaces_all()
call Whitespaces_trailing()
call Whitespaces_consecutive()
call Whitespaces_lines()
endfunction
" Map F9 to execute the custom function
nnoremap <F9> :call Whitespaces()<CR>
nnoremap <F9> :call Whitespaces_all()<CR>
" entferne trailing whitespaces beim speichern
autocmd BufWritePre * :call Whitespaces_trailing()
" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif