vim: function whitespaces
This commit is contained in:
parent
58c554a7e9
commit
9bb6fb8e49
1 changed files with 18 additions and 9 deletions
25
.vimrc
25
.vimrc
|
@ -234,15 +234,24 @@ nnoremap <Leader>z :set nonumber! norelativenumber!<CR>
|
|||
: 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
|
||||
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
|
||||
" 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
|
||||
|
||||
" 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.
|
||||
|
|
Loading…
Reference in a new issue