Skip to content

Add history to prompt buffer#19700

Open
64-bitman wants to merge 1 commit intovim:masterfrom
64-bitman:prompt_history
Open

Add history to prompt buffer#19700
64-bitman wants to merge 1 commit intovim:masterfrom
64-bitman:prompt_history

Conversation

@64-bitman
Copy link
Copy Markdown
Contributor

@64-bitman 64-bitman commented Mar 15, 2026

Fixes #5010. Adds history to the prompt buffer, like a command line shell. Will add tests later

@puremourning what are your thoughts on this? Thanks.

@64-bitman 64-bitman force-pushed the prompt_history branch 4 times, most recently from d126ed6 to ac5f3c8 Compare March 16, 2026 00:39
@64-bitman 64-bitman force-pushed the prompt_history branch 6 times, most recently from a1baab6 to f9002eb Compare March 16, 2026 02:04
Copy link
Copy Markdown
Member

@chrisbra chrisbra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only looked at the provided API, but I think this can be improved.


If "max" is not provided, then the entire history is returned.
The first item in the list is always the current text (text
that has not been entered yet by the user). Use a "max" value
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
that has not been entered yet by the user). Use a "max" value
If "max" is not provided, then the entire history is returned. The list order is always from the most recent entry to the oldest, with the very first item in the list being the current text on the prompt line (which may be an empty string if nothing has been typed).


Return type: |String|

prompt_gethistory({buf} [, {max}]) *prompt_gethistory()*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different from e.g. histget(). Is this inconsistency okay?

none set prompt history
prompt_sethistsize({buf}, {max})
Number set maximum number of items in prompt
history
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am looking at the existing history functions: histget(), histadd(), histdel() and histnr(). I think we should use a naming, prompt_hist<action>

moving through the prompt history.

In both cases, the values will be clamped between the maximum
and minimum possible offsets or indexes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clamped is a bit unusual in the help files, how about this:

In both cases, the value is limited to the available range:
If the index or offset would move the position beyond the oldest
entry or past the current text, it will stay at the first or
last entry respectively. No error is given.

{only available when compiled with the |+channel| feature}

prompt_histsearch({buf}, {offset} [, {text}]) *prompt_histsearch()*
Search for a specific entry in the prompt history and set the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Search for a specific entry in the prompt history and set the
Search for a specific entry {text} in the prompt history and set the

world!
inprogress| <current position>
< To go to "hello" is history, do >vim
call prompt_histsearch(bufnr(), 2, "he")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit strange. The function is called search, why do we need to provide an offset?


prompt_histsearch({buf}, {offset} [, {text}]) *prompt_histsearch()*
Search for a specific entry in the prompt history and set the
current text. {buf} can be a buffer name or number. See
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this not just return a list of history entries or the indexes? Why set the text? That is what the goto function is for, no?


prompt_sethistsize({buf}, {max}) *prompt_sethistsize()*
Set the maximum prompt history size of {buf} to "max". {buf}
can be a buffer name or number. See |prompt-buffer|.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be an option?

GetBuffer()->prompt_setinterrupt(callback)
<
Return type: |Number|

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this removed?

@64-bitman
Copy link
Copy Markdown
Contributor Author

I have only looked at the provided API, but I think this can be improved.

Yes. I would also like feedback from @puremourning if they are available

@puremourning
Copy link
Copy Markdown
Contributor

puremourning commented Mar 18, 2026

I checked it quickly. Need to think about it practically. Might take me a little while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make <up>/<down> arrow keys navigate previous insertions in prompt buffers

4 participants