Re: ":b {bufname}" tab-completion uses whole filepath

Gary Johnson <[email protected]>
Newsgroups gmane.editors.vim
Message-ID <20240614193251.GA15474@phoenix>
On 2024-06-14, Enan Ajmain wrote:
> I use ':b' quite often.  And I use a substring of the bufname to jump to
> that buffer.  Works quite well.
> 
> But a problem is that the substring I provide isn't only matched with
> the buffer names but also the filenames.  See these examples:
> 
>     :ls
>       1 #h   "example\predict.py"           line 25
>       2  a   "deeplog\deeplog.py"           line 0
>       4 %a   "example\train.py"             line 37
>     :b deep<tab>
> 
> Then when I type ":b deep<tab>", the matches shown are:
> 
>     E:\projects\log-parsing\deeplog\example\predict.py
>     deeplog\deeplog.py
>     E:\projects\log-parsing\deeplog\example\train.py
> 
> We can see that vim is matching the filepaths instead of only the buffer
> names.  Can I change this behavior?  Preferably with vimscripting, but
> I'm willing to change source code too since I use this too often.
> 
> To be clear: I want only this match to be shown:
> 
>     deeplog\deeplog.py

The full buffer name _is_ the full file name.  Vim usually tries to
show the user a shorter name such as the relative file name.  If, in
your example, you were to :cd to some other directory and execute
:ls again, you would see those buffer names as full path names.

I don't know of a built-in command or option that will give you what
you want.  I think you would have to write a function that would
search the buffer list for a buffer whose basename or relative path
contained the substring you supplied and execute the :b command with
that name.  Just the bufname() function with the appropriate
file-pattern would do a lot of the work.

You could then create a command to call that function.  The command
name would have to begin with an upper-case letter, but you can also
use :cabbrev to create an abbreviation that expands 'b' at the
beginning of the command line to your command name.  That would let
you continue to use the :b command that your fingers are used to.

For <tab> to work, you'd also need to create a completion function
that followed the same matching rules as your buffer function.

Maybe not simple, but doable in vimscript.

HTH,
Gary

-- 
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20240614193251.GA15474%40phoenix.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.