]> gitweb.fluxo.info Git - rhatto/dotfiles/vim.git/commitdiff
Feat: adds TrimWhitespace()
authorSilvio Rhatto <rhatto@riseup.net>
Tue, 30 Jul 2024 03:44:53 +0000 (00:44 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Tue, 30 Jul 2024 03:44:53 +0000 (00:44 -0300)
vim.dot.link/plugin/key_mappings.vim
vim.dot.link/plugin/lib.vim

index 2b0f2e792a088e6a70aec5da41dba270b8279e4b..0c8bfbad3803d8e0328662465fe914dda8073b8c 100644 (file)
@@ -245,3 +245,7 @@ nnoremap <leader>d i<C-R>=strftime('%Y-%m-%d')<CR>
 inoremap <leader>d <C-R>=strftime('%Y-%m-%d')<CR>
 map <leader>e :put =strftime('## %Y-%m-%d')<CR>
 " }}}
+
+" Remove trailing whitespaces {{{
+noremap <leader>w :call TrimWhitespace()<CR>
+" }}}
index 0e4cafadc6cc9ab0b06671e698a6b09ad4c77181..9e7b6894cd4443a62af39c97c2e79c408196aa7d 100644 (file)
 "    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()