1

In a BufWritePre to remove trailing spaces, my function uses a search/replace for \s\+$ over the current buffer. So after saving any buffer, this weird entry \s\+$ shows up in my search history. Is there a way to search-and-do-not-append-history? Or can a search history entry be automatically deleted (for example, the most recent entry)?

9
  • do you have a plugin for removing trailing whitespace? Commented Oct 14, 2020 at 11:49
  • It's in my .vimrc (which I figured out about 3 seconds after posting), so I changed the question, since it is still a problem. Commented Oct 14, 2020 at 11:52
  • 3
    :h :keeppatterns Commented Oct 14, 2020 at 11:59
  • @ChristianBrabandt thanks, that works. So I tried googling for something like this, and found absolutely nothing related. Is there a better way to find out about features in vim? There's no way I can read about them all because it would take a year, and by then I would forget what I read. Commented Oct 14, 2020 at 12:13
  • This may not be the answer you want to hear but learning how to do effective google searching will get you quite far. I found keeppatterns on my first google search and it's the top result. The search term: "vim don't overwrite search history". Top result: Vim search without overwriting "/ register (In this case the search term was quite straightforward, TBH. What did you look for, if you don't mind saying?)
    – B Layer
    Commented Oct 14, 2020 at 21:38

1 Answer 1

2

Perhaps you have an autocommand that is searching for trailing whitespace on save? That is what \s\+$ is searching for.

1
  • yes, that was it, and I changed the question accordingly. Commented Oct 14, 2020 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.