rgroli/other.nvim

Pattern matching not working?

Closed this issue · 1 comments

Hi, thanks for this useful small plugin.

So I have these two rules:

{
	context = "lua main module",
	pattern = ".*.lua$",
	target = ".*/init.lua",
},
{
	context = "file of same name, but in different directory",
	pattern = ".*/(.-)$",
	target = ".*/%1",
},

The first one should switch from any lua file to the main module. It works fine, and the pattern work as expected.

However, the second case does not work as expected, given a file foobar.lua, it should switch to a different file with the same name, but in an (unspecified) other directory, for example:

pwd: ~/.config/nvim

# current
lua/foo/foobar.lua

# target
lua/baz/foobar.lua

Trying the pattern manually with vim.fn.expand("%"):match(".*/(.-)$") gives the expected result of foobar.lua, and then trying vim.fn.expand("%"):match(".*/foobar.lua$") matches the target file.

I am not sure whether I am misunderstanding something here about how the patterns work in this plugin or whether this is a bug with the matching implementation of this plugin? 🤔

@chrisgrieser For the target you could try:

target = ".**/%1",

with ** searching through different subdirs. That should do the trick