[vim/vim] [Proposal] Add histignorecase option (#7872)

33 views
Skip to first unread message

obcat

unread,
Feb 19, 2021, 5:54:23 AMFeb 19
to vim/vim, Subscribed

Is your feature request about something that is currently impossible or hard to do? Please describe the problem.

It is difficult to recall recent command-line from history, whose beginning matches the cuurrent command-line by "case-insensitive" way.

Describe the solution you'd like

Add a new option like histignorecase. When this is set, case is ignored when recalling command-line from history by <Up> and <Down>.

Describe alternatives you've considered
I can use the histget(), getcmdline(), and match() to achieve this feature. For example, something like this.

cnoremap <Up>   <C-\>eUpIgnorecase()<CR>
cnoremap <Down> <C-\>eDownIgnorecase()<CR>

function UpIgnorecase()
  " Use above functions to return cmdline whose beginning matches current cmdline by case-insensitive way. 
endfunction
function DownIgnorecase()
  " ...
endfunction

But there is one problem. The <Up> and <Down> are used to go up and down the directory or menu when the wildmenu is used to complete filename or menu:

	While the "wildmenu" is active the following keys have special
	meanings:

	<Left> <Right>	- select previous/next match (like CTRL-P/CTRL-N)
	<Down>		- in filename/menu name completion: move into a
			  subdirectory or submenu.
	<CR>		- in menu completion, when the cursor is just after a
			  dot: move into a submenu.
	<Up>		- in filename/menu name completion: move up into
			  parent directory or parent menu.

I want to keep this feature, so I need to do something like this:

cnoremap <expr> <Up>   {is completing filename or menu with wildmenu} ? '<Up>'   : '<C-\>eUpIgnorecase()<CR>'
cnoremap <expr> <Down> {is completing filename or menu with wildmenu} ? '<Down>' : '<C-\>eUpIgnorecase()<CR>'

However, AFAIK, there is no way to get whether {is completing filename or menu with wildmenu} or not.

To get this, I propose that wildmenumode() with |non-zero-arg| returns what the current completion is for. For example, when completing filename, wildmenumode(1) returns file. For this return value, the second argument of the getcompletion() would be suitable:

		arglist		file names in argument list
		augroup		autocmd groups
		buffer		buffer names
		behave		:behave suboptions
		color		color schemes
		command		Ex command (and arguments)
		cmdline		|cmdline-completion| result
		compiler	compilers
		cscope		|:cscope| suboptions
		diff_buffer     |:diffget| and |:diffput| completion
		dir		directory names
		environment	environment variable names
		event		autocommand events
		expression	Vim expression
		file		file and directory names
		file_in_path	file and directory names in |'path'|
		filetype	filetype names |'filetype'|
		function	function name
		help		help subjects
		highlight	highlight groups
		history		:history suboptions
		locale		locale names (as output of locale -a)
		mapclear	buffer argument
		mapping		mapping name
		menu		menus
		messages	|:messages| suboptions
		option		options
		packadd		optional package |pack-add| names
		shellcmd	Shell command
		sign		|:sign| suboptions
		syntax		syntax file names |'syntax'|
		syntime		|:syntime| suboptions
		tag		tags
		tag_listfiles	tags, file names
		user		user names
		var		user variables

This allows me to do what I want to do in the following way:

cnoremap <expr> <Up>   wildmenumode(1) is 'file' || wildmenumode(1) is 'menu' ? '<Up>'   : '<C-\>eUpIgnorecase()<CR>'
cnoremap <expr> <Down> wildmenumode(1) is 'file' || wildmenumode(1) is 'menu' ? '<Down>' : '<C-\>eDownIgnorecase()<CR>'


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Bram Moolenaar

unread,
Feb 19, 2021, 3:54:34 PMFeb 19
to vim/vim, Subscribed

I believe you only intend to ignore case in the command argument. ":edit" and ":Edit" would still be different.

I actually would like this to be more clever. E.g. when typing ":e file" and pressing it would also find ":edit filemore". Also ignoring extra colons or white space, which cause no semantic difference.

obcat

unread,
Feb 19, 2021, 9:11:55 PMFeb 19
to vim/vim, Subscribed

I believe you only intend to ignore case in the command argument. ":edit" and ":Edit" would still be different.

I intend to ignore case in the whole keyword rather than only the command argument. For example, suppose that the output of :history :is as follows:

      #  cmd history
      1  edit foo.txt
      2  Edit bar.txt
      3  edit baz.txt
      4  Edit qux.txt
>     5  history :

I want to be able to type :edit b and press Up to complete :edit baz and press Up again to complete :Edit bar.txt.

I actually would like this to be more clever. E.g. when typing ":e file" and pressing it would also find ":edit filemore". Also ignoring extra colons or white space, which cause no semantic difference.

That sounds good! It would be interesting to add a new option like histsearchopt to change the behavior of Up / Down in the cmdline-mode so that we can specify something like set histsearchopt=ignorecase or set histsearchopt=clever.

Yegappan Lakshmanan

unread,
Feb 19, 2021, 9:19:34 PMFeb 19
to vim_dev, reply+ACY5DGH2U26QHJGJKK...@reply.github.com, vim/vim, Subscribed
Hi,

On Fri, Feb 19, 2021 at 6:12 PM obcat <vim-dev...@256bit.org> wrote:

I believe you only intend to ignore case in the command argument. ":edit" and ":Edit" would still be different.

I intend to ignore case in the whole keyword rather than only the command argument. For example, suppose that the output of :history :is as follows:

      #  cmd history
      1  edit foo.txt
      2  Edit bar.txt
      3  edit baz.txt
      4  Edit qux.txt
>     5  history :

I want to be able to type :edit b and press Up to complete :edit baz and press Up again to complete :Edit bar.txt.

I actually would like this to be more clever. E.g. when typing ":e file" and pressing it would also find ":edit filemore". Also ignoring extra colons or white space, which cause no semantic difference.

That sounds good! It would be interesting to add a new option like histsearchopt to change the behavior of Up / Down in the cmdline-mode so that we can specify something like set histsearchopt=ignorecase or set histsearchopt=clever.



Based on the description, it looks like you are looking for fuzzy search. We should
add 'fuzzymatch' to 'wildoptions' and enable fuzzy completion for all the commands.

Regards,
Yegappan
 

vim-dev ML

unread,
Feb 19, 2021, 9:19:56 PMFeb 19
to vim/vim, vim-dev ML, Your activity

obcat

unread,
Feb 19, 2021, 9:43:11 PMFeb 19
to vim/vim, vim-dev ML, Comment

Based on the description, it looks like you are looking for fuzzy search.
We should
add 'fuzzymatch' to 'wildoptions' and enable fuzzy completion for all the
commands.

I only intended to change the behavior of c_<Up> and c_<Down> for forward match search in the cmdline-history, but it is interesting to add a new item to wildoptions to change the behavior of c_wildchar and c_CTRL-D as well!


You are receiving this because you commented.

Yegappan Lakshmanan

unread,
Feb 21, 2021, 4:59:15 PMFeb 21
to vim_dev, reply+ACY5DGF2ICOMT7VFM3...@reply.github.com, vim/vim, vim-dev ML, Comment
Hi,

On Fri, Feb 19, 2021 at 6:43 PM obcat <vim-dev...@256bit.org> wrote:

Based on the description, it looks like you are looking for fuzzy search.
We should
add 'fuzzymatch' to 'wildoptions' and enable fuzzy completion for all the
commands.

I only intended to change the behavior of c_<Up> and c_<Down> for forward match search in the cmdline-history, but it is interesting to add a new item to wildoptions to change the behavior of c_wildchar and c_CTRL-D as well!



I have implemented the fuzzy match based completion for several 
different completion types at:


Fuzzy match completion for file names is not supported yet though.

- Yegappan

vim-dev ML

unread,
Feb 21, 2021, 4:59:42 PMFeb 21
to vim/vim, vim-dev ML, Your activity

obcat

unread,
Feb 21, 2021, 11:00:25 PMFeb 21
to vim/vim, vim-dev ML, Comment

I have implemented the fuzzy match based completion for several
different completion types at:

https://github.com/yegappan/vim/tree/wildopt

Wow! Thank you very much. I'll try it later.


You are receiving this because you commented.

Shane-XB-Qian

unread,
Feb 22, 2021, 5:10:13 AMFeb 22
to vim/vim, vim-dev ML, Comment

@yegappan i tried.. looks nice, though.....

  • compared to ignorecase, this 'fuzzy' probably listed massive items, not sure if everyone like it..
  • cannot set/work with cur 'tagfile' option, looks was exclusive each other.. was it intended?
  • it is 'matchfuzzy', not 'fuzzymatch', expression in ticket is diff like in code, may confused someone..
  • yea, so far looks canNot compl for file names (if there uppercase letters in fs name)..

anyway, looking forward it..


You are receiving this because you commented.

Yegappan Lakshmanan

unread,
Feb 22, 2021, 11:24:52 AMFeb 22
to vim_dev, reply+ACY5DGEJAALELDWGNT...@reply.github.com, vim/vim, vim-dev ML, Comment
Hi,

Thanks for trying the patch.

On Mon, Feb 22, 2021 at 2:10 AM Shane-XB-Qian <vim-dev...@256bit.org> wrote:

@yegappan i tried.. looks nice, though.....

  • compared to ignorecase, this 'fuzzy' probably listed massive items, not sure if everyone like it..
Yes. Depending on the search pattern, fuzzy matching may find more completion
items than a regular expression. But the returned results are sorted by the
match score. So the item with the highest matching score is listed first.

  • cannot set/work with cur 'tagfile' option, looks was exclusive each other.. was it intended?

Are you referring to the tag completion? Fuzzy matching is currently not supported
for tag name completion.
 
  • it is 'matchfuzzy', not 'fuzzymatch', expression in ticket is diff like in code, may confused someone..
We can change the item in 'wildoptions' to 'fuzzymatch' or just 'fuzzy'.
 
  • yea, so far looks canNot compl for file names (if there uppercase letters in fs name)..

anyway, looking forward it..


Fuzzy matching is currently supported for completing items that are not
file names or tag names.

Regards,
Yegappan
 

vim-dev ML

unread,
Feb 22, 2021, 11:25:15 AMFeb 22
to vim/vim, vim-dev ML, Your activity

Hi,

Thanks for trying the patch.

On Mon, Feb 22, 2021 at 2:10 AM Shane-XB-Qian <vim-dev...@256bit.org>
wrote:

> @yegappan <https://github.com/yegappan> i tried.. looks nice, though.....
>
> - compared to ignorecase, this 'fuzzy' probably listed massive items,

> not sure if everyone like it..
>
> Yes. Depending on the search pattern, fuzzy matching may find more
completion
items than a regular expression. But the returned results are sorted by the
match score. So the item with the highest matching score is listed first.


> - cannot set/work with cur 'tagfile' option, looks was exclusive each

> other.. was it intended?
>
>
Are you referring to the tag completion? Fuzzy matching is currently not
supported
for tag name completion.


>
> - it is 'matchfuzzy', not 'fuzzymatch', expression in ticket is diff

> like in code, may confused someone..
>
> We can change the item in 'wildoptions' to 'fuzzymatch' or just 'fuzzy'.


>
> - yea, so far looks canNot compl for file names (if there uppercase

> letters in fs name)..
>
> anyway, looking forward it..
>

Fuzzy matching is currently supported for completing items that are not
file names or tag names.

Regards,
Yegappan

Shane-XB-Qian

unread,
Feb 22, 2021, 11:53:48 AMFeb 22
to vim/vim, vim-dev ML, Comment

Are you referring to the tag completion?

Yes, and means combined wildoption as fuzzy plus tagfile.

// looks somewhere had such similar feature, I like it, wish this would be applied ASAP. :-)


You are receiving this because you commented.

obcat

unread,
Feb 22, 2021, 6:20:48 PMFeb 22
to vim/vim, vim-dev ML, Comment

Hi, I also tried... It's working fine! I hope this feature is introduced.

@brammool Any thoughts about this?


You are receiving this because you commented.

Shane-XB-Qian

unread,
Mar 3, 2021, 3:55:40 AMMar 3
to vim/vim, vim-dev ML, Comment

compared to 'ignorecase', made 'fuzzy' as an option into wildoption looks much good, i felt 'ignorecase' impacted too much if set...
@brammool @yegappan any thoughts to merge this?


You are receiving this because you commented.

Bram Moolenaar

unread,
Mar 3, 2021, 10:55:08 AMMar 3
to vim/vim, vim-dev ML, Comment

We should consider some tweaking before including this.


You are receiving this because you commented.

Shane-XB-Qian

unread,
Mar 3, 2021, 10:59:58 AMMar 3
to vim/vim, vim-dev ML, Comment

sure, understood.. just felt it would help user speed up typing cmd much, i think.. :-)
// but it's ok to wait, or withdraw if it had outage..


You are receiving this because you commented.

Yegappan Lakshmanan

unread,
Mar 3, 2021, 11:15:45 AMMar 3
to vim_dev, reply+ACY5DGGTBSK4CKW6YK...@reply.github.com, vim/vim, vim-dev ML, Comment
Hi,

On Wed, Mar 3, 2021 at 12:55 AM Shane-XB-Qian <vim-dev...@256bit.org> wrote:
>
> compared to 'ignorecase', made 'fuzzy' as an option into wildoption looks much good, i felt 'ignorecase' impacted too much if set...
> @brammool @yegappan any thoughts to merge this?
>

I need to add tests for the fuzzy completion support for these commands
and update the help text. I will then create a PR.

Note that as mentioned previously, the fuzzy completion currently doesn't
work for file names and tag names. The file name completion code is pretty
complex. So the fuzzy completion for filenames needs to be added in a
separate PR.

- Yegappan

vim-dev ML

unread,
Mar 3, 2021, 11:16:07 AMMar 3
to vim/vim, vim-dev ML, Your activity

Shane-XB-Qian

unread,
Mar 3, 2021, 11:57:40 AMMar 3
to vim/vim, vim-dev ML, Comment

On 21/03/03 08:16AM, vim-dev ML wrote:
> Hi,
>
> On Wed, Mar 3, 2021 at 12:55 AM Shane-XB-Qian <vim-dev...@256bit.org> wrote:
> >
> > compared to 'ignorecase', made 'fuzzy' as an option into wildoption looks much good, i felt 'ignorecase' impacted too much if set...
> > @brammool @yegappan any thoughts to merge this?
> >
>
> I need to add tests for the fuzzy completion support for these commands
> and update the help text. I will then create a PR.
>
> Note that as mentioned previously, the fuzzy completion currently doesn't
> work for file names and tag names. The file name completion code is pretty
> complex. So the fuzzy completion for filenames needs to be added in a
> separate PR.
>
> - Yegappan

actually, i felt fuzzy completion for filenames is not much useful, since it
can complete from parent folder to sub folder one to one already..

compared to so, fuzzy completion for tag names is more helpful than filenames..

or Neither of them, :-) cmd fuzzy completion is most helpful..

--
shane.xb.qian


You are receiving this because you commented.

Shane-XB-Qian

unread,
Sep 23, 2021, 11:25:15 PMSep 23
to vim/vim, vim-dev ML, Comment

@yegappan is it good time to merge this fuzzy complete now? :-)
// fuzzy complete for filename probably not much useful, but cmd (or tag as well) looks more useful.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

Reply all
Reply to author
Forward
0 new messages