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

Add vimtex-env-create #2489

Closed
cnut1648 opened this issue Sep 18, 2022 · 9 comments
Closed

Add vimtex-env-create #2489

cnut1648 opened this issue Sep 18, 2022 · 9 comments

Comments

@cnut1648
Copy link

First of all, I have been using vimtex for a few days and this plugin is absolutely amazing!!!! Thank you so much for this plugin and it makes my note-taking experience better than ever!!

Is your feature request related to a problem? Please describe it.
Currently there is a vimtex-cmd-create which is mapped to F7 by default. I personally find it very useful in that I can visually select text and hit one F7 to wrap the whole selected text in a command.

I think it will be equally useful if we can have a counterpart for environment so that users can also wrap selected text in an environment.

Describe the solution you'd like
Add a vimtex-env-create command.

Describe alternatives you've considered
My current workaround is to use Utisnips, here is my snip:

snippet beg "begin{} / end{}" bA
\\begin{$1}
	${VISUAL}
\\end{$1}
endsnippet

To do so I would have to first enter into visual mode, select text, hit tab and type beg and tab again, which is ok but a little annoying. With vimtex-env-create command I can map it to, say, <F5> and voila.

Thank you for reading.

@lervag
Copy link
Owner

lervag commented Sep 20, 2022

First of all, I have been using vimtex for a few days and this plugin is absolutely amazing!!!! Thank you so much for this plugin and it makes my note-taking experience better than ever!!

Thanks for the kind words! :)

I think it will be equally useful if we can have a counterpart for environment so that users can also wrap selected text in an environment.

Describe the solution you'd like Add a vimtex-env-create command.

I've previously thought this should be left to a snippet engine. However, I can see that this, although solveable by a snippet engine, could also warrant a feature of its own in VimTeX. We would want this workflow, right:

  • Visual mode: Select text, press <f5>, write the name of an environment, then VimTeX adds \begin{name} in a line above and \end{name} in a line below the selection. Preferably it should be properly indented, so we might also adjust indents accordingly.
  • Normal mode: press <f5> to surround current line with an environment.

Perhaps we should call it vimtex-env-create-surrounding to make it more clear?

@Alexandre867
Copy link

Alexandre867 commented Sep 26, 2022

I'm using UltiSnips too and I've found a workaround for wrapping around some selected text using some mapping here. You could adapt it to wrap around as an environment.

In my ~\vimfiles\ftplugin\tex.vim:

vnoremap <buffer> <C-S-E> :call UltiSnips#SaveLastVisualSelection()<CR>gvs#<C-R>=UltiSnips#ExpandSnippet()<CR>
inoremap <buffer> <C-S-E> #<C-R>=UltiSnips#ExpandSnippet()

In my ~\vimfiles\UltiSnips\tex.snippets:

snippet # "Put in brackets" i
\\${1:emph}{${VISUAL}$2}$0
endsnippet

@lervag
Copy link
Owner

lervag commented Sep 26, 2022

@cnut1648 Any comments about my suggestion?

@cnut1648
Copy link
Author

Hi @lervag, this sounds really great! This is exactly what I was looking for. The indentation part is good, as for now I have to manually add the indentation in the snippet engine.

@cnut1648
Copy link
Author

@Alexandre867 oh interesting. I never knew we can make non-ascii characters the trigger. This certainly gives us more options for this functionality. But I personally still feel a vimtex built-in is easier to manage.

lervag added a commit that referenced this issue Sep 29, 2022
@lervag
Copy link
Owner

lervag commented Sep 29, 2022

I've added an initial version of this. Please test and give some feedback. The relevant docs: :help vimtex-env-surround-line. Notice that the default map is <F6>.

@lervag lervag closed this as completed Sep 29, 2022
@cnut1648
Copy link
Author

cnut1648 commented Oct 2, 2022

Thanks @lervag! I've been using it for a day and it is good!!

@lervag
Copy link
Owner

lervag commented Oct 3, 2022

Glad to hear it!

@lukasz-r
Copy link

I've been using an older version of VimTeX and got used to pressing for environment insert. I switched to the newest version and I'm glad to see it's back, though mapped to , but that's not a problem. A great feature.

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

4 participants