From 4a858add914d5bd680a27fd0f135bc67c219413c Mon Sep 17 00:00:00 2001 From: McAuleyPenney <134115@gmail.com> Date: Thu, 28 Oct 2021 09:11:35 -0700 Subject: [PATCH] [docs,feat]: protect search history and jump list - add `keepjumps` and `keeppatterns` modifiers to regex commands - update readme --- lua/tidy/init.lua | 8 +++----- readme.md | 3 +++ 2 files changed, 6 insertions(+), 5 deletions(-) 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