2

Is there a way edit command line or search history? I have read Is there search and replace history in vim? and tried using q: to open the history and do changes there, but all it seems to be able to do is take an edited line, execute it and append it to the history.

What I want to do is just replace a line in history (in-place) without necessarily executing it.

Use case: I try to create a plugin, that appends words under the cursor to the search (when the user presses a button). The most part is done by changing the @/ register. But I also want to update the original search command so that a user can actually find the command that would issue the modified search. I could simply re-execute the search, but then the history would get flooded.

Example:

Buffer: This is some fine text in the buffer.

User enters: "/some", the cursor goes to "some" and the last line in search history will contain "/some". Then, the user moves the cursor to "text", presses a certain key and text is added to the search term. So now, the search term would be "/some\|text".

I would like to change/overwrite the last line in search history to be "/some\|text".

  • I imagine you could use histadd(), histget(), and histdel() function to create such a behavior. See :h histadd() – Peter Rincker Mar 15 '18 at 15:03
  • @PeterRincker: Hey, this is exactly what I was looking for. Thank your! And it seems to be available in NeoVim as well. NICE! If you make that an answer, I'll accept it. – mox Mar 15 '18 at 16:49
2

You can edit the search history with the following,: histadd(), histget(), and histdel().

See :h histadd() for more help.

0

Vim stores both the command history and the search history and many other things like registers and jumplists in ~/.viminfo. You can remove/edit entries from the history by deleting/changing the corresponing lines in the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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