From 891fae907b9bed937bd7619a9b0fee6293451aee Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Sat, 2 Oct 2021 13:01:04 +0530 Subject: [PATCH] nvim: plugin: Add a simple whitespace plugin Now that we dropped vim-better-whitespace just add something simple to strip whitespace if we do ever need it. --- nvim/.config/nvim/plugin/whitespace.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 nvim/.config/nvim/plugin/whitespace.vim diff --git a/nvim/.config/nvim/plugin/whitespace.vim b/nvim/.config/nvim/plugin/whitespace.vim new file mode 100644 index 0000000..203a2be --- /dev/null +++ b/nvim/.config/nvim/plugin/whitespace.vim @@ -0,0 +1,12 @@ +" https://vi.stackexchange.com/questions/454/whats-the-simplest-way-to-strip-trailing-whitespace-from-all-lines-in-a-file +function! Preserve(command) + " Preparation: save window state + let l:saved_winview = winsaveview() + " Run the command: + execute a:command + " Clean up: restore previous window position + call winrestview(l:saved_winview) +endfunction + +nnoremap ws :call Preserve("%s/\\s\\+$//e") +xnoremap ws :call Preserve("%s/\\s\\+$//e")