Sunday, June 23, 2024

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

On 2024-06-14, Enan Ajmain <3nan.ajmain@gmail.com> 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, --

If you don't mind using a (lightweight) plugin, you can do it with my
Zeef¹ plugin. Zeef has a buffer switcher, which may or may not work for
you, but simplifying the creation of one tailored to your own specific
needs is the very purpose of the plugin. This is an example:

vim9script
import autoload 'zeef.vim'

def SwitchToBuffer(items: list<string>)
execute 'buffer' matchstr(items[0], '^\s*\zs\d\+')
enddef

zeef.Open(
execute('ls')->split("\n"),
SwitchToBuffer,
'Choose buffer',
{multi: false},
)

Hope this helps,
Life.

¹ https://github.com/lifepillar/vim-zeef



--
--
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 vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/v599m0%248b7%241%40ciao.gmane.io.

No comments:

Post a Comment