diff --git a/.vimrc b/.vimrc index 7ee678d..c7dba3e 100644 --- a/.vimrc +++ b/.vimrc @@ -234,15 +234,24 @@ nnoremap z :set nonumber! norelativenumber! : autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif :augroup END -" entferne trailing whitespaces beim speichern -autocmd BufWritePre * :%s/\s\+$//e -" entferne multiple consecutive empty lines -if executable('cat') - autocmd BufWritePre *.md silent %!cat -s -endif -" remove multiple whitespaces between words -" https://stackoverflow.com/questions/5150870/efficient-way-to-remove-multiple-spaces-between-two-words-in-Vim -autocmd BufWritePre *.md :%s/\(\w\)\s\+\(\w\)/\1 \2/g +function! Whitespaces() + " Remove trailing whitespace + %s/\s\+$//e + + " Replace consecutive spaces between words with a single space (only for .md files) + if &filetype == "markdown" + %s/\(\w\)\s\+\(\w\)/\1 \2/g + endif + + " Run silent command to remove multiple consecutive empty lines (only for .md files) + if &filetype == "markdown" + silent %!cat -s + endif +endfunction + +" Map F9 to execute the custom function +nnoremap :call Whitespaces() + " Exit Vim if NERDTree is the only window remaining in the only tab.