martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.2k stars 258 forks source link

Don't store duplicates in command history #993

Closed adigitoleo closed 2 years ago

adigitoleo commented 2 years ago

I didn't seen this explicitly mentioned (could have missed it), but it would be nice if the command buffer didn't store duplicates. Some commands are used fairly frequently, e.g. :w, and it tends to clutter the command buffer after some time.

jpaulogg commented 2 years ago

The wiki says that:

:, / and ? prompt implemented as a regular file/window with custom key bindings.

So every text you put in the command prompt becomes a line of a regular file. I like this behaviour because you can search for text using / and ? and even complete words with <C-n>.

adigitoleo commented 2 years ago

Right, that's nice. However, I think this could be preserved while also avoiding duplicates. The check would need to be performed before the line is added.

EDIT: Ah, I see, it's literally just insert mode in a regular buffer. This would require a whole extra layer in between then. Maybe not worth it.

adigitoleo commented 2 years ago

If I get time to look into vis-menu, I guess I could set up some custom keybindings to cycle through previous "commands" (i.e. lines of the command buffer) while skipping duplicates or something like that. Sorry for the noise.

jpaulogg commented 2 years ago

If I get time to look into vis-menu, I guess I could set up some custom keybindings to cycle through previous "commands" (i.e. lines of the command buffer) while skipping duplicates or something like that. Sorry for the noise.

You could use a plugin for line completion. I wrote one myself.

ninewise commented 2 years ago

It might also be possible to have a WIN_OPEN event on the command window which removes duplicates.

adigitoleo commented 2 years ago

It might also be possible to have a WIN_OPEN event on the command window which removes duplicates.

True, I'd just need some way to detect the command window. That doesn't seem to be exposed to the API yet, so this would have to be done internally.