From bc9e269bd03f749c0d482f8c8c1677382d0bbb8d Mon Sep 17 00:00:00 2001 From: mg Date: Tue, 29 Aug 2023 08:32:53 +0200 Subject: [PATCH] vim: whitespaces --- .vimrc | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/.vimrc b/.vimrc index bccbaf5..b49fce7 100644 --- a/.vimrc +++ b/.vimrc @@ -236,25 +236,33 @@ nnoremap z :set nonumber! norelativenumber! : 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 :call Whitespaces() - - +nnoremap :call Whitespaces_all() +" 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