[docs,feat]: protect search history and jump list

- add `keepjumps` and `keeppatterns` modifiers to regex commands
    - update readme
main
McAuleyPenney 3 years ago
parent 9acc5686ce
commit 4a858add91

@ -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 )

@ -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

Loading…
Cancel
Save