vim: function whitespaces
This commit is contained in:
parent
58c554a7e9
commit
9bb6fb8e49
1 changed files with 18 additions and 9 deletions
27
.vimrc
27
.vimrc
|
@ -234,15 +234,24 @@ nnoremap <Leader>z :set nonumber! norelativenumber!<CR>
|
||||||
: autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif
|
: autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif
|
||||||
:augroup END
|
:augroup END
|
||||||
|
|
||||||
" entferne trailing whitespaces beim speichern
|
function! Whitespaces()
|
||||||
autocmd BufWritePre * :%s/\s\+$//e
|
" Remove trailing whitespace
|
||||||
" entferne multiple consecutive empty lines
|
%s/\s\+$//e
|
||||||
if executable('cat')
|
|
||||||
autocmd BufWritePre *.md silent %!cat -s
|
" Replace consecutive spaces between words with a single space (only for .md files)
|
||||||
endif
|
if &filetype == "markdown"
|
||||||
" remove multiple whitespaces between words
|
%s/\(\w\)\s\+\(\w\)/\1 \2/g
|
||||||
" https://stackoverflow.com/questions/5150870/efficient-way-to-remove-multiple-spaces-between-two-words-in-Vim
|
endif
|
||||||
autocmd BufWritePre *.md :%s/\(\w\)\s\+\(\w\)/\1 \2/g
|
|
||||||
|
" 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 <F9> :call Whitespaces()<CR>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
" Exit Vim if NERDTree is the only window remaining in the only tab.
|
" Exit Vim if NERDTree is the only window remaining in the only tab.
|
||||||
|
|
Loading…
Reference in a new issue