Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace special characters in search rules #495

Closed
ghost opened this issue Nov 13, 2021 · 14 comments
Closed

Replace special characters in search rules #495

ghost opened this issue Nov 13, 2021 · 14 comments

Comments

@ghost
Copy link

ghost commented Nov 13, 2021

I would like to replace special characters (e.g. "á", "à") in url for standard ones (e.g. "a"). It doesn't work like this:

e|ex|example|: https://www.example.com/%S \
  re=/[^a-zA-Z0-9_-]/g

So, how should I do it?

@gdh1995
Copy link
Owner

gdh1995 commented Nov 14, 2021

Sorry but I don't understand what you wanted. Do you want to "type e á on Vomnibar and then search e a"?

Then you may add this to the Auto substitution of various text option:

o/á/a/g
o/b'/b/g
# and so on

o means omni and g is a RegExp flag, and you may see https://github.com/gdh1995/vimium-c/wiki/Substitute-URLs-and-text-during-commands .

If you want a single line to convert all accented characters, you need to wait for a next version, and I'll add latin into substitution actions.

@gdh1995
Copy link
Owner

gdh1995 commented Nov 14, 2021

Edit. Sorry Auto substitution of various text has a bug since v1.94.0, so I'll fix it in days.

To work around the bug, you may write O/á/a/g (use the upper-case version of keys).

@gdh1995 gdh1995 added the bug label Nov 14, 2021
@ghost
Copy link
Author

ghost commented Nov 15, 2021

I'm trying to type something in the Vomnibar and have it replaced according to a regexp, yeah, but I'm trying to use it for custom search parameters. And O/á/a/g doesn't seem to be working either. Am I writing it correctly?

# Custom search engines
ex: https://example.com/%s \ 
  re=O/á/a/g

I guess I should be placing it in Auto substitution of various text's box instead, right?

O/á/a/g,host=example.com

@gdh1995
Copy link
Owner

gdh1995 commented Nov 16, 2021

Yes on the substitution textbox.

@gdh1995
Copy link
Owner

gdh1995 commented Nov 16, 2021

re= on the search engine part is not to do so. It should be a valid RegExp and is used to extract search words (https://github.com/gdh1995/vimium-c/wiki/Search-engine-rules#parsing-regexp-pattern)

@ghost
Copy link
Author

ghost commented Nov 16, 2021

I know this is not related to this issue, but suppose I wanted to build the following URL:

https://www.example.com/terms/g/grossproduct.asp

It has the initial letter of the search parameter (g) between slashes and before the parameter. Is this achievable within the custom search feature? Is it possible to capture the first character of a search parameter and insert it somewhere else in the URL?

I'm currently working around it like this:

ex: https://www.example.com/terms/%s{$1/$2}.asp

where $1 is the first letter, while $2 is the search parameter.

@gdh1995
Copy link
Owner

gdh1995 commented Nov 17, 2021

t: vimium://sed/c,@(.),$1/$1,\ https://www.example.com/terms/@$s

This means to:

  1. replace $s with your query (let's say it's gross)
  2. get vimium://sed/c,@(.),$1/$1, https://www.example.com/terms/@gross
  3. run sed (substitution) with a rule of c,@(.),$1/$1, so @g will be replaced by g/g for once.
  4. Then return https://www.example.com/terms/g/gross.

@ghost
Copy link
Author

ghost commented Nov 17, 2021

Interesting. What does vimium:// mean? Can I use it everywhere in Vimium C's options?

@gdh1995
Copy link
Owner

gdh1995 commented Nov 17, 2021

Only those places which accept normal URLs. See https://github.com/gdh1995/vimium-c/wiki/Vimium-inner-URLs

@ghost ghost closed this as completed Nov 17, 2021
@ghost ghost reopened this Nov 17, 2021
@gdh1995
Copy link
Owner

gdh1995 commented Jan 11, 2022

Hello, you may take a try with Vimium C v1.96.3 on Firefox Add-Ons, which has fixed some bugs of text substitution and supported o/^//,latin

@gdh1995 gdh1995 closed this as completed Feb 3, 2022
@ghost
Copy link
Author

ghost commented Aug 14, 2022

O/ã/a/g,host=example.com/

How do I make the code above replace the parameter that comes after the / in host? I want it to translate the input ex ação in the vomnibar to the URL https://www.example.com/açao/ in the browser's omnibar. Is it already possible to add more characters to the regexp and replacement fields (e.g. ãáàâõôóöç/aaaaooooc)?

@gdh1995
Copy link
Owner

gdh1995 commented Aug 15, 2022

The host parameter expects a value of a valid URL hostname, so its value should be not example.com/ but example.com, or you may just remove the host parameter to make this rule be applied on other websites' URLs.

In a latest version of Vimium C, o/^//,latin should be enough to convert all latin letters into English latters, and if you only want to apply it on URLs of example.com, you may write o/^//,latin,host=example.com

@ghost
Copy link
Author

ghost commented Aug 15, 2022

In a latest version of Vimium C, o/^//,latin should be enough to convert all latin letters into English latters, and if you only want to apply it on URLs of example.com, you may write o/^//,latin,host=example.com

It doesn't work. I have version 1.98.3 installed and I'm using Edge.

I have the following options set up:
image
image
image

The URL ends up being https://www.dicio.com.br/a%c3%a7%c3%a3o/

@gdh1995
Copy link
Owner

gdh1995 commented Aug 15, 2022

Um, it can be fixed by declaring such a search engine: dic|dicio: vimium://sed/o%20https://dicio.com.br/%s .

The root cause is:

  1. when you press Enter on Vomnibar, it uses URL of the auto-selected "search" suggestion item and tries to open it
  2. since it's the suggestion item, but not a raw query to open, Vimium C doesn't apply the o substitution rules on the URL.
  3. then o/^//,latin is never used.
  4. on the contrary, if you don't type any keyword on Vomnibar, then the query will be converted to "acao"

The new search engine I write above can force Vimium C to execute those substitution rules labelled o.

And the change can even be shorter:

dic|dicio: vimium://sed/o/^//,latin%20https://dicio.com.br/%s

This embeds the substitution rule of o/^//,latin into the search URL, so you can even omit the step to change Auto substitution of various text.

====

Or you may use another way to force Vomnibar to execute substitution rules when you want to open a suggestion item, by:

map o Vomnibar.activate itemSedKeys="o"

And then Vomnibar will apply "o" rules on both raw query and all suggestion items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant