diff --git a/lua/tidy/init.lua b/lua/tidy/init.lua index 6babc40..45e7697 100644 --- a/lua/tidy/init.lua +++ b/lua/tidy/init.lua @@ -1,7 +1,5 @@ -- MP --- These sources did all the work --- 1. https://vim.fandom.com/wiki/Remove_unwanted_spaces#Automatically_removing_all_trailing_whitespace --- 2. https://stackoverflow.com/a/7501902 + local M = {} @@ -12,10 +10,10 @@ function M.tidy_up() local pos = vim.api.nvim_win_get_cursor( 0 ) -- delete all whitespace, see source 1 - vim.cmd[[:%s/\s\+$//e]] + vim.cmd[[:keepjumps keeppatterns %s/\s\+$//e]] -- delete all lines at end of buffer, see source 2 - vim.cmd[[:silent! 0;/^\%(\n*.\)\@!/,$d]] + vim.cmd[[:keepjumps keeppatterns silent! 0;/^\%(\n*.\)\@!/,$d]] -- get row count after line deletion local end_row = vim.api.nvim_buf_line_count( 0 ) diff --git a/readme.md b/readme.md index 2603eaf..0b895f2 100644 --- a/readme.md +++ b/readme.md @@ -14,3 +14,6 @@ https://user-images.githubusercontent.com/59481467/138811091-05031eb1-96fc-4915- Credits: 1. [Vim Tips Wiki entry for removing unwanted spaces](https://vim.fandom.com/wiki/Remove_unwanted_spaces#Automatically_removing_all_trailing_whitespace) 2. ib., the author of [this stack overflow answer](https://stackoverflow.com/a/7501902) +3. [This line](https://github.com/gpanders/editorconfig.nvim/blob/ae3586771996b2fb1662eb0c17f5d1f4f5759bb7/lua/editorconfig.lua#L180) +in [gpanders/editorconfig.nvim](https://github.com/gpanders/editorconfig.nvim) for exposing me to the `keepjumps` +and `keeppatterns` modifiers