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

Ignore accents #173

Closed
dbmrq opened this issue Jun 3, 2016 · 12 comments
Closed

Ignore accents #173

dbmrq opened this issue Jun 3, 2016 · 12 comments
Assignees

Comments

@dbmrq
Copy link
Contributor

dbmrq commented Jun 3, 2016

I don't know how hard it would be to do this, but it would be really really great if Sneak could consider characters with or without accents as the same.
Just now I wanted to go to the word "ética", for instance, and I instinctively tried Sneak with et, but it doesn't work. This happens to me all the time.

PS: I love Sneak, thanks for making it!

@justinmk
Copy link
Owner

justinmk commented Jun 3, 2016

I think this is what :lnoremap is for. Let's merge this with #138

If you really like this kind of thing, easymotion probably has a feature for it already, I think. The goal of sneak is less "do what I mean" (DWIM) and more narrow.

Thanks too :)

@dbmrq
Copy link
Contributor Author

dbmrq commented Jun 3, 2016

I've tried easymotion, but I don't like it as much. :/

lmap is just like a regular mapping but for more than one mode, isn't it? Maybe I'm missing something, but I don't see how that's relevant.
What I want in my example is that Sneak et would match not only "ét", but both "et" and "ét".

Here I mapped f to use one-character Sneak and did fo:

sneak

Here I'd hope "ó", "õ" and "ô" to be highlighted too.

I think what we would need is something like this: http://vi.stackexchange.com/a/7394

Searching for [[=e=]] matches "e", "é", "ê" and so on. So we'd need an option that would cause Sneak to search for [[=e=]] when you type e, [[=a=]] when you type a etc. I don't see any drawbacks in doing this (except perhaps for the performance of the plugin), but it could be changed with an option anyway.

I don't use lmap or keymap, I use combining characters for accents, so to type "ética" I actually type 'etica. Sneak doesn't count 'e as "é", though, so I can't search for that character at all, and the same goes for all accented characters. And even if that did work it would require an extra key stroke. Using collection classes would fix that and many other possible problems IMHO, making Sneak a lot more flexible.

This would even be useful for english speakers I think… there are many loan words from french, for instance, and what would you do if you wanted to go to the word résumé? It would be a lot easier to just do Sneak re.

@justinmk justinmk reopened this Jun 3, 2016
@justinmk
Copy link
Owner

justinmk commented Jun 3, 2016

Hmm, equivalence class looks useful. It shouldn't be much code to support this so I'll keep it open.

@dbmrq
Copy link
Contributor Author

dbmrq commented Jun 3, 2016

Great, thanks! 🎉

@dbmrq
Copy link
Contributor Author

dbmrq commented Jun 3, 2016

I can try to implement this if you want, but I don't know much about Vimscript, so I'd need some help.

Now I just looked into your search.vim and tried replacing the line that says

    let self.search = escape(a:input, '"\')

with

    let self.search = substitute(a:input, '\a', '[[=\0=]]', 'g')

But it doesn't work, I don't know why. Doing that never get any matches anymore.

@justinmk
Copy link
Owner

justinmk commented Jun 3, 2016

Sorry, it might be awhile before I can help with this.

@dbmrq
Copy link
Contributor Author

dbmrq commented Jun 3, 2016

No problem, I'll keep trying and I'll post here if I get anywhere, and you can look into it whenever you have the time. Thanks again. :)

@dbmrq
Copy link
Contributor Author

dbmrq commented Jun 3, 2016

Aha! I think I got it.

The problem was the escaping, and then I tried to escape just the characters in the original code, "\, but it wasn't working.

Besides escaping those characters, now I tried adding a backslash before the whole equivalence class too:

    let escapedstring = escape(a:input, '"\')
    let self.search = substitute(escapedstring, '\a', '\\[[=\0=]]', 'g')

And it works! Here's sae:

captura de tela 2016-06-03 as 18 09 39

I also tried some other random characters, slashes, quotes, braces, it seems like it's all working as it should.

I didn't make a PR already because I don't know if this has any unintended consequences or if there's something else we'd have to change too, I got to this via wild guesses and I'm not familiar with the rest of the code at all. But if you think it's alright I can make a PR too.

For now I'll keep using it like this and if anything weird shows up I'll let you know.

@justinmk
Copy link
Owner

justinmk commented Jun 4, 2016

Nice! Try it for a few days and let me know. This is simple enough that it's worth adding.

@dbmrq
Copy link
Contributor Author

dbmrq commented Jul 5, 2016

Ok, I used this a lot over the last month and it seems to be working great. :)
I still don't know why it needed that extra back slash, but it works perfectly and it made sneak a hundred times better for me.
Should I make a PR or something?

@justinmk justinmk self-assigned this Jul 18, 2016
@justinmk
Copy link
Owner

@danielbmarques PR would be welcome.

@ggandor
Copy link
Contributor

ggandor commented Apr 18, 2021

In case someone is reading this now and interested: the extra backslash at the beginning of '\\[[=\0=]]' is necessary because the final search pattern is very nomagic (self.prefix sets \V), but we need a collection-delimiting pair of brackets (\[]) around the equivalence class, not literal ones.

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

3 participants