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

Is there any way to use tsd to toggle delimiters in insert mode? #2445

Closed
pilgrimlyieu opened this issue Jul 30, 2022 · 8 comments
Closed

Is there any way to use tsd to toggle delimiters in insert mode? #2445

pilgrimlyieu opened this issue Jul 30, 2022 · 8 comments

Comments

@pilgrimlyieu
Copy link

Is your feature request related to a problem? Please describe it.

<plug>(vimtex-delim-toggle-modifier) is useful. However, it will be better if I can toggle it as soon as I insert delimiters in insert mode.

Describe the solution you'd like

Support using <plug>(vimtex-delim-toggle-modifier) or any other way to enable a key mapping for insert mode.

Thanks!

@lervag
Copy link
Owner

lervag commented Jul 31, 2022

I've pushed a minor fix just now. With this, you can create that map yourself. The following example should work:

imap <f7> <esc><plug>(vimtex-delim-toggle-modifier)a

I would add this in one of two ways:

  1. Add it to your personal ftplugin/tex.vim. This is what I recommend.

  2. Alternatively, add the mapping in your vimrc or init.vim file under an autocommand, something like this:

    augroup vimrc
      autocmd!
      autocmd FileType tex imap <f7> <esc><plug>(vimtex-delim-toggle-modifier)a
    augroup END

This way, you only apply the mapping when VimTeX is loaded.

@lervag lervag closed this as completed Jul 31, 2022
@pilgrimlyieu
Copy link
Author

That works.

However, it will change the position of the cursor. Here is an example.

imap <f7> <esc><plug>(vimtex-delim-toggle-modifier)a
$$
(aaa)<cursor>
$$

Then press F7.

$$
\left(aaa\right)<cursor>
$$

Press again.

$$
(<cursor>aaa)
$$

lervag added a commit that referenced this issue Aug 2, 2022
@lervag
Copy link
Owner

lervag commented Aug 2, 2022

Sorry, there was a minor error in the positioning calculation. I've fixed it now, please test again.

@pilgrimlyieu
Copy link
Author

Sorry, there was a minor error in the positioning calculation. I've fixed it now, please test again.

That works. But still has a minor issue.

$$
\{aaa\}<cursor>
$$

Then press F7.

$$
\left\{aaa\right\<cursor>}
$$

Press again.

$$
\{aaa\<cursor>}
$$

@lervag
Copy link
Owner

lervag commented Aug 3, 2022

Thanks; nice edge case. I'll fix it as soon as I get the time!

lervag added a commit that referenced this issue Aug 11, 2022
@lervag
Copy link
Owner

lervag commented Aug 11, 2022

I believe this should be fixed now, please test.

@pilgrimlyieu
Copy link
Author

pilgrimlyieu commented Aug 13, 2022

I believe this should be fixed now, please test.

Thanks! Works now.

@lervag
Copy link
Owner

lervag commented Aug 13, 2022

Great, glad to hear it!

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

2 participants