lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.55k stars 390 forks source link

Provide user option to use sandwich.vim mappings everywhere (and disable it by default) #2098

Closed krishnakumarg1984 closed 3 years ago

krishnakumarg1984 commented 3 years ago

Vimtex's documentation states:

VimTeX provides mappings that change, delete and toggle commands, delimiters and environments (see the ds, cs and ts family of mappings listed under |vimtex-default-mappings|). These mappings are inspired by the great surround.vim [0] |surround.txt|) by Tim Pope, which provides mappings to manipulate surrounding delimiters such as '', "", (), [], {}, and <>. As such, the mappings from VimTeX should work well together with, and as an extension of, surround.vim. Consider also the customization described under |vimtex-faq-surround|. The mappings may be repeated with the dot (|.|) command. See also |g:vimtex_delim_list| if you are interested in customizing the delimiter pairs that are recognized.

In the very next paragraph, the documentation mentions the related sandwich.vim. I am a sandwich.vim user. Now, the default mappings of sandwich begins with s instead of the action. This leads to an inconsistent split usage model for the user, wherein some mappings use sandwich semantics while others adhere to the surround.vim scheme provided by vimtex.

It would ease the cognitive burden on the user if vimtex can provide a boolean option such as let g:vimtex_use_sandwich_mapping_scheme can be provided (which is set to 0 by default to maintain backward compatibility). The ideas is to detect that sandwich is loaded and switch to its mnemonic scheme. i.e. dsc shall become sdc etc.

yongrenjie commented 3 years ago

@krishnakumarg1984 I also use sandwich, and the commands sdc, saac, saic, etc. already work for me. Does it not work for you?

yongrenjie commented 3 years ago

Perhaps, you need to install the targets.vim plugin as well for this to work (I already have it installed). Even without targets.vim, most of the sandwich operators + vimtex text objects combinations work mostly fine, although I found that ic doesn't really behave right. I'm not an expert on this, but :h g:vimtex_text_obj_variant has some info.

krishnakumarg1984 commented 3 years ago

Weirdly, I have only dsc, dse etc working. I will look at bit further into it when I start writing again this weekend.

Secondly, it is not clear from vimtex's documentation that using sandwich (with default mappings) shall automatically switch vimtex's mappings from dsc to sdc, or from dse to sde etc.

The *s* mappings are hard-coded everywhere in the documentation. For instance, in the mappings table:

   dse              |<plug>(vimtex-env-delete)|                     `n`
   dsc              |<plug>(vimtex-cmd-delete)|                     `n`
   ds$              |<plug>(vimtex-env-delete-math)|                `n`
   dsd              |<plug>(vimtex-delim-delete)|                   `n`
   cse              |<plug>(vimtex-env-change)|                     `n`
   csc              |<plug>(vimtex-cmd-change)|                     `n`
   cs$              |<plug>(vimtex-env-change-math)|                `n`
   csd              |<plug>(vimtex-delim-change-math)|              `n`
   tsf              |<plug>(vimtex-cmd-toggle-frac)|                `nx`
   tsc              |<plug>(vimtex-cmd-toggle-star)|                `n`
   tse              |<plug>(vimtex-env-toggle-star)|                `n`
   tsd              |<plug>(vimtex-delim-toggle-modifier)|          `nx`
   tsD              |<plug>(vimtex-delim-toggle-modifier-reverse)|  `nx`

And a few other places (towards the top of the help file, the README.md on GitHub etc). I suspect this is because the ds* mappings are inspired by tpope's surround.vim which predates sandwich.vim by nearly 6-7 years, and the documentation just didn't get updated when sandwich support was added later on.

yongrenjie commented 3 years ago

Hmm... I think I understand the situation a bit better now, sorry. There are several things which are subtly different. The first thing is the text objects ic/ac/ie/ae, which you would use for example using saic (but you could also do cic, dic, vic or yic for example). This is provided by vimtex.

The second thing is the explicit mappings which you mentioned, including dsc. These are vimtex-specific, too.

On the other hand, sandwich also defines its own c and e 'recipes', see :h sandwich-filetype-recipes. This is what enables the c insdc or the e in sde. I think these should be enabled by default, if you didn't disable it and it's not working for you, then I suspect that's a sandwich issue, not vimtex.

This can get a bit messy, because for example if I want to add a nested command (let's say change \textit{hello} to \textit{\textbf{hello}} I would do saicc then textbf<CR>. The first ic is using vimtex's text object, the second c is using sandwich's filetype recipes.

BTW, vimtex doesn't switch any mappings, AFAIK. I don't think that sandwich is explicitly supported by vimtex. dsc and dse still work for me, I just don't use them. The commands sdc and sde also do work for me, but this is because of the sandwich filetype recipes, not because of vimtex.

lervag commented 3 years ago

In the very next paragraph, the documentation mentions the related sandwich.vim. I am a sandwich.vim user. Now, the default mappings of sandwich begins with s instead of the action. This leads to an inconsistent split usage model for the user, wherein some mappings use sandwich semantics while others adhere to the surround.vim scheme provided by vimtex.

It would ease the cognitive burden on the user if vimtex can provide a boolean option such as let g:vimtex_use_sandwich_mapping_scheme can be provided (which is set to 0 by default to maintain backward compatibility). The ideas is to detect that sandwich is loaded and switch to its mnemonic scheme. i.e. dsc shall become sdc etc.

This might be a good idea. Reasons it might not:

It would be very helpful if yuo (or anyone else interested in this) could show me the proper list of mappings required.

BTW, vimtex doesn't switch any mappings, AFAIK.

Correct.

I don't think that sandwich is explicitly supported by vimtex.

Correct. That is, sandwich works well with VimTeX and there is no conflic, so there is some kind of implicit support, I guess?

dsc and dse still work for me, I just don't use them. The commands sdc and sde also do work for me, but this is because of the sandwich filetype recipes, not because of vimtex.

Yes, I believe these exist and work quite well. Perhaps also the cse and csc variants, although I believe VimTeX may have better completion here. I also believe the csd may be "better" in VimTeX.