Shougo / neosnippet.vim

neo-snippet plugin
Other
1.12k stars 108 forks source link

Add <Plug>(neosnippet_foo) to expand/jump in n/xmap #486

Closed aileot closed 4 years ago

aileot commented 4 years ago

This PR will let users to map them easier.

I only use <Plug>(neosnippet_expand_or_jump) so I've not check the others work. I'm sorry for the irresponsibility.

Shougo commented 4 years ago

Why the PR is needed?? Please describe it more clearly with examples.

And please update the documentation.

aileot commented 4 years ago

This PR is for easier configuration for users; small differences between similar texts often confuse us in a feature review, and drive us to search through documentations even when we are not naive in the field.

Sometimes we leave Insert Mode while a snippet's unfinished. In such a case, I often want to jump and restart to replace the next place-holder in the snippet. I believe some other users do, too.

Without this commit, we should write a script like below to enable such a motion within a key lke <C-\>

imap <C-\> <Plug>(neosnippet_expand_or_jump)
smap <C-\> <Plug>(neosnippet_expand_or_jump)

nmap <C-\> <c-g>h<Plug>(neosnippet_expand_or_jump)
xmap <C-\> <c-g><Plug>(neosnippet_expand_or_jump)

This lacks parity. But with this commit, we can configure like below.

nmap <C-\> <Plug>(neosnippet_expand_or_jump)
imap <C-\> <Plug>(neosnippet_expand_or_jump)
vmap <C-\> <Plug>(neosnippet_expand_or_jump)

" or with no care to `:omap`; however, it fails to remove any place-holder though it can jump anyway. Do you see the reason?
map  <C-\> <Plug>(neosnippet_expand_or_jump)
imap <C-\> <Plug>(neosnippet_expand_or_jump)

Don't you feel it easier with this example rather than the former?

Of course, I'll update the documentation as long as you make sure to accept this PR.

Shougo commented 4 years ago

Hm. OK. I accept the PR. Please update the documentation.

aileot commented 4 years ago

OK. I will.

By the way, would you explain the difference between <Plug>(neosnippet_expand_or_jump) and <Plug>(neosnippet_jump_or_expand) here.

There seems no explanation about it in the help, and I only use <Plug>(neosnippet_expand_or_jump) as I said above.

If you write it in this thread, I will paste it in my fork and make a commit. It would be bothersome to merge/rebase and so on.

Shougo commented 4 years ago

expand_or_jump means check expand before jump. jump_or_expand means check jump before expand.

aileot commented 4 years ago

OK. It was a matter of the priority after all. I will mention to it in the documentation, too.

aileot commented 4 years ago

I've updated the documentation.

May I replace <Plug>(...expand_or_jump) with <Plug>(...jump_or_expand) in the examples of the documentation? I recently found unexpected expansions sometimes happen while editing a snippet.

In my consideration, it is more complex usage to expand rather than to jump, and documentation should be written close to naive users who expect simpler usage.

Shougo commented 4 years ago

In my consideration, it is more complex usage to expand rather than to jump, and documentation should be written close to naive users who expect simpler usage.

You can improve the documentation later.