1

I use vimtex although I am by no means an expert in Vim, so it may be that I'm missing something obvious. Anyway, I am looking for functionality similar to that of 'cse, csc, csd' (which change the surrounding environment, command, or delimiter respectively) where instead of changing something I would like to add an environment, command, or delimiter around some text highlighted in say visual mode.

The place I find myself most often needing this is when I quickly import a graphic and then have to go back and wrap the command in a center environment. This also sometimes comes up when I have a variable say t which I've forgotten to drop in math mode (so it appears as a non-math t). It's a pain to do `insert mode -> $ -> exit insert mode -> l -> insert mode -> $' and I'm sure there is an easier way, but I haven't been able to find it.

There were a couple of good suggestions on a post I made at the LaTeX stack exchange, but was told to come here for something more official.

3
  • VimTeX does not really have this built in, except for the <plug>(vimtex-cmd-create) mapping (default mapped to F7) which works similar to what you ask for for commands. I believe plugins like surround.vim or vim-sandwich and snippet plugins like UltiSnips are better tools for this feature. Aug 1, 2021 at 11:25
  • Hi Karl, thanks for the input! I indeed have had good luck with using surround as suggested. Also, I'm sure you get this a lot, but thanks so much for keeping vimtex updated!
    – Lockjaw
    Aug 1, 2021 at 23:17
  • Thanks for using it :) Aug 3, 2021 at 6:53

1 Answer 1

2

If you're using vim-surround from tpope, there are the following:

  • ys<TARGET>l or ys<TARGET>l will prompt for a \begin{ environment
  • ys<TARGET>$ will surround with dollar-signs

You can also use S in visual mode, along with other keys as shown in :help surround.

2
  • It looks like the visual mode functionality I was requesting is also a feature (using S). I think that would be a good addition to the answer!
    – Lockjaw
    Jul 27, 2021 at 21:51
  • @Lockjaw added. The help is great for this stuff
    – D. Ben Knoble
    Jul 27, 2021 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.