lervag / vimtex

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

Wrong indent for \item when using Ultisnips #1245

Closed goduck777 closed 5 years ago

goduck777 commented 5 years ago

Vimtex can handle the indent of \item very will in most cases.

In Ultisnips (or other snippet plugins), there is a very convenient way to input \item. Like, I can just type it\<tab> to get a \item. However, in this case vimtex gives the wrong indent. The tab before \item is not eliminated. The result is like

\item a
    \item b
        \item c

Is there a fix for this problem? or is there a better way for inputting \item?

lervag commented 5 years ago

The reason for this is that the current line is reindented on certain specified keys, which are not typed when you do it<tab>. Thus the tab before the \item will not be removed.

Personally, I've solved this particular issue by defining a mapping for inserting the items, i.e. I have the following in my personal ftplugin/tex.vim (can also be put in ftplugin/after/tex.vim).

call vimtex#imaps#add_map({
      \ 'lhs' : '<m-i>',
      \ 'rhs' : '\item ',
      \ 'leader'  : '',
      \ 'wrapper' : 'vimtex#imaps#wrap_environment',
      \ 'context' : [
      \   'itemize',
      \   'enumerate',
      \   {'envs' : ['description'], 'rhs' : '\item['},
      \ ],
      \})

However, Ultisnips is powerful, and I'm sure you can solve this with it as well. I'm no expert, but it seems this might be close to what you want to do.

lervag commented 5 years ago

I'm closing the issue, but feel free to continue the discussion.

goduck777 commented 5 years ago

Thank you for your answer. This is not exactly what I want. I am looking for auto-indenting the line after the snippet expand. The ultisnips trick you suggests gives a fixed indent, but not a smart indent according to the context.

I will submit an issue to ultisnips for this problem.

lervag commented 5 years ago

Ok, thanks. Feel free to make a reference to the Ultisnips issue when/if you create it.

andymass commented 5 years ago

@goduck777 there is already this possibly related issue https://github.com/SirVer/ultisnips/issues/913

goduck777 commented 5 years ago

@andymass Thank you, this is what I want.

cuppajoeman commented 2 years ago

@lervag Why does vimtex autoindent after a line containing \item? Is there a way to disable that.

lervag commented 2 years ago

@cuppajoeman Please don't ask new questions in old threads. It is much better to open a new issue.

The why: Because I've found it convenient to "descramble" the \item lines from the remaining lines in itemize environments. That is, because I like it this way. But of course, it is configurable. The details are explained in :help g:vimtex_fold_types. For your convenience: SNIPPET REMOVED

EDIT: Remove erroneous statement about configurability.

fxmarty commented 2 years ago

@lervag The command would be let g:vimtex_fold_types = {'items' : {'enabled' : 0}} according to the doc I believe, and as for me, it does not work.

(i.e., when pressing ENTER in an itemize environment, I get an additional indent like

\item blabla (ENTER pressed)
        | <--- now here :-(
lervag commented 2 years ago

Sorry, my mistake. The g:vimtex_fold_... is of course not relevant for indents. Thus, there is currently no option to disable this kind of indentation. Feel free to open a feature request if you believe this would be a valuable feature.

fxmarty commented 2 years ago

@lervag Thanks a lot

amine-aboufirass commented 2 years ago

It would be nice to be able to disable this. Is it still not possible?

lervag commented 2 years ago

@awa5114 This was never opened as a feature request. If you want it, please open a feature request and describe what you want.