aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vim.dot.link/plugin/key_mappings.vim4
-rw-r--r--vim.dot.link/plugin/lib.vim11
2 files changed, 15 insertions, 0 deletions
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 <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>
+" }}}
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()