Comments (9)
I will update the documentation about this. The characters which need to be escaped are:
( ) . % + - * ? [ ^ $
at least as far as I can tell according to this: https://www.lua.org/pil/20.2.html
When you're also using a capturing-group for the path part (like mentioned above) maybe you could get rid of escaping all together.
from other.nvim.
the string you're matching against already contains the escaping. Shouldn't it be?
vim.pretty_print(
(
'/Users/ahmed/Some/deeply/nested/folder/structure/here/foo/bar/v10/some-folder/file.ts'
):match '/foo/bar/v10/some%-folder/(.*).ts$'
)
from other.nvim.
Ahh I see π
okay!strange enough it works nevertheless in my testcase. Anyway I updated the comment, thanks!
from other.nvim.
You're doing it right!
the thing is that in your case there is a "-" in the path. In lua you need to escape this with "%". So the working pattern would be:
require('other-nvim').setup {
mappings = {
{
pattern = '/foo/bar/v10/some%-folder/(.*).ts$',
target = '/foo/bar/v10/tests/some-folder/%1.test.ts',
},
{
pattern = '/foo/bar/v10/tests/some%-folder/(.*).test.ts$',
target = '/foo/bar/v10/some-folder/%1.ts',
},
},
}
I will update the documentation about this. Thank you for the hint!
Another thing you could do to optimize your pattern is making the "some-folder"-part dynamic too. Like that:
require('other-nvim').setup {
mappings = {
{
pattern = '/foo/bar/v10/(.*)/(.*).ts$',
target = '/foo/bar/v10/tests/%1/%2.test.ts',
},
{
pattern = '/foo/bar/v10/tests/(.*)/(.*).test.ts$',
target = '/foo/bar/v10/%1/%2.ts',
},
},
}
I haven't tested that - but it should work
from other.nvim.
the thing is that in your case there is a "-" in the path. In lua you need to escape this with "%"
I was sure it was something silly like thisβ¦ π thanks! do you have a list of characters that need to be escaped in lua? Or maybe a resource about this?
Because in my case the absolute URL contains a lot of folders with -
so I assume I need to escape all of them? because it's still not working for me.
Maybe this should be baked in the plugin?
from other.nvim.
Not sure what I'm doing wrong but this still returns nil
vim.pretty_print(
(
'/Users/ahmed/Some/deeply/nested/folder/structure/here/foo/bar/v10/some%-folder/file.ts'
):match '/foo/bar/v10/some%-folder/(.*).ts$'
)
from other.nvim.
Thanks, it works now ππΌ
I think your example here needs to be fixed, because I followed that one #4 (comment)
from other.nvim.
Great that it works now!
but honestly I don't know how to fix the example above. I just tried that with a directory structure that mimiks yours and it just works.
require('other-nvim').setup {
mappings = {
{
pattern = '/foo/bar/v10/some%-folder/(.*).ts$',
target = '/foo/bar/v10/tests/some%-folder/%1.test.ts',
},
{
pattern = '/foo/bar/v10/tests/some%-folder/(.*).test.ts$',
target = '/foo/bar/v10/some%-folder/%1.ts',
},
},
}
from other.nvim.
This is the only change needed, you escaped the -
inside target
while this is only needed inside pattern
require('other-nvim').setup {
mappings = {
{
pattern = '/foo/bar/v10/some%-folder/(.*).ts$',
- target = '/foo/bar/v10/tests/some%-folder/%1.test.ts',
+ target = '/foo/bar/v10/tests/some-folder/%1.test.ts',
},
{
pattern = '/foo/bar/v10/tests/some%-folder/(.*).test.ts$',
- target = '/foo/bar/v10/some%-folder/%1.ts',
+ target = '/foo/bar/v10/some-folder/%1.ts',
},
},
}
from other.nvim.
Related Issues (20)
- Add built-in mappings for Golang HOT 2
- Not work on next.js & sveltekit HOT 11
- How to contribute
- Let :Other accept file path as an argument HOT 2
- Mapping the current directory HOT 3
- Suggesting repeated other spec files HOT 1
- Suggestion: Open as tab HOT 1
- Suggestion: Support for Angular Services HOT 1
- Not working with negative lookbehind regex pattern HOT 1
- [SUGGESTION] c{,pp} header and source files HOT 1
- Pattern matching not working? HOT 1
- Command to open the file picker without clearing the internal reference HOT 1
- Question: What's the syntax used in target field? HOT 1
- Use custom highlight groups HOT 1
- If `filePickerBeforeShow` returns false or an empty table, do nothing HOT 1
- Keep default openCommand when invoking `OtherSplit` et al. and selecting in picker HOT 2
- Question: do not specify match group in 'target' HOT 1
- Expose local findOther function as API HOT 4
- [Feature request]: Allow setting the shortcut char on the mapping HOT 1
- [Feature] Add spec patterns to default rails mappings HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from other.nvim.