easymotion / vim-easymotion

Vim motions on speed!
http://www.vim.org/scripts/script.php?script_id=3526
7.49k stars 362 forks source link

Feature: User defined dictionary including 2-chars dict #135

Open haya14busa opened 10 years ago

haya14busa commented 10 years ago

Like migemo & smartsign feature.

let g:EasyMotion_user_dict  = {
            \ 'e' : '[eæœèéêëēėęěə]',
            \ 'nn' : '\v\c(nn|\d\+)',
            \ '??' : '[!"#$%&''()=~|\-^\\@`[\]{};:+*<>,.?_/]',
}
haya14busa commented 10 years ago

This feature is for find motions. e.g. <Plug>(easymotion-s), <Plug>(easymotion-f), etc..

haya14busa commented 10 years ago

branch: https://github.com/Lokaltog/vim-easymotion/tree/feature/user-dictionary

haya14busa commented 10 years ago

Should I consider filetype?

haya14busa commented 10 years ago

Sample?:

let g:EasyMotion_userdict = {
\ '_' : {
\     'dd' : '\d\+'
\   , '??' : '\v[!"#$%&''()=~|\-^\\@`[\]{};:+*<>,.?_/]+'
\   , 'bb' : '\v[()[\]{}]+'
\   , 'ee' : '[eæœèéêëēėęěə]'
\   , 'ww' : '\(\<.\|^$\)'
\   , '$$' : '$'
\   , 'jk' : '^\(\w\|\s*\zs\|$\)'
\   },
\ 'vim' : {
\     'fn' : '\<fu\%[nction]!\=\s\+\%(<[sS][iI][dD]>\|[sSgGbBwWtTlL]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)*\ze\s*('
\   },
\ 'python' : {
\     'fn' : '^\s*def\s\+\h\w*\s*('
\   }
\ }
DmitryOtroshchenko commented 8 years ago

My use case is jumping to any punctuation sign by typing an easily reachable wildcard character so I have drafted this feature by introducing proxy symbols dictionary:

let g:EasyMotion_proxy_symbols = {';': '!@#$%^&*()-_=+\|:;''"[]{},<.>?/~'}

I use Coleman layout so ; is easily reachable for me.

The implementation is trivial for 1-char substitutions, however I see two possible approaches to implementing the 2-char dictionary feature:

let g:EasyMotion_userdict = { 'dd' : '\d\+', 'ee' : '[eæœèéêëēėęěə]' }

Typing ddee will match any digit followed by any e-like character. However there exists no way to distinguish ddee from dde apart from triggering motion after some timeout or ENTER. This approach will require modification of EasyMotion command line processing and may be more challenging to implement. In addition it may lead to ambiguous cases.

@haya14busa Could you please tell me the vision of this feature?

haya14busa commented 8 years ago

branch: https://github.com/easymotion/vim-easymotion/issues/135#issuecomment-42261158

Thank you for the comment :+1: I have no plan to support more than two character. If you want something like that, use https://github.com/haya14busa/incsearch-easymotion.vim and create pattern converter module for incsearch.vim (e.g. https://github.com/haya14busa/incsearch-fuzzy.vim) n-char search motion considers input as regex, so it's difficult to support user dict feature.

But, we can apply same logic to one-character dict for 2-char search. I prefer 1-character dict also applies to 2-char search.

DmitryOtroshchenko commented 8 years ago

I already use incsearch-easymotion and incsearch-fuzzy. Thank you very much for excellent plugins!

I also agree with the simplified approach no mater 1-char or 2-char combination is used: it will permit to avoid ambiguity. Thus with:

let g:EasyMotion_userdict = { 'dd' : '\d\+', 'ee' : '[eæœèéêëēėęěə]' }

dd will be transform into any digit by easymotion-s2 motion.

But how do you imagine using 2-char substitutions in easymotion-f and easymotion-t?