From c0c227d51a3caf5502eac6bd65ab01117f12d29a Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 30 Jul 2024 00:44:53 -0300 Subject: Feat: adds TrimWhitespace() --- vim.dot.link/plugin/key_mappings.vim | 4 ++++ vim.dot.link/plugin/lib.vim | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/vim.dot.link/plugin/key_mappings.vim b/vim.dot.link/plugin/key_mappings.vim index 2b0f2e7..0c8bfba 100644 --- a/vim.dot.link/plugin/key_mappings.vim +++ b/vim.dot.link/plugin/key_mappings.vim @@ -245,3 +245,7 @@ nnoremap d i=strftime('%Y-%m-%d') inoremap d =strftime('%Y-%m-%d') map e :put =strftime('## %Y-%m-%d') " }}} + +" Remove trailing whitespaces {{{ +noremap w :call TrimWhitespace() +" }}} diff --git a/vim.dot.link/plugin/lib.vim b/vim.dot.link/plugin/lib.vim index 0e4cafa..9e7b689 100644 --- a/vim.dot.link/plugin/lib.vim +++ b/vim.dot.link/plugin/lib.vim @@ -19,3 +19,14 @@ " call setline('.', substitute(line, '- ', '- \[ \] ', '')) " endif "endf + +" Remove trailing spaces +" +" Thanks https://vi.stackexchange.com/a/456 +fun! TrimWhitespace() + let l:save = winsaveview() + keeppatterns %s/\s\+$//e + call winrestview(l:save) +endfun + +command! TrimWhitespace call TrimWhitespace() -- cgit v1.2.3