0

The ftplugin vimtex provides the file indent/tex.vim with following line

setlocal indentkeys+=[,(,{,),},],\&,=item,=else,=fi

'indentkeys' 'indk' string (default "0{,0},:,0#,!^F,o,O,e")
local to buffer
A list of keys that, when typed in Insert mode, cause reindenting of the current line. Only happens if 'indentexpr' isn't empty. The format is identical to 'cinkeys', see |indentkeys-format|.

Consider this list environment:

\begin{itemize}
  \item <CURSOR> 
\end{itemize} 

When you enter a newline and then a second \item, at first the cursor will be indented to the second level (sw=2)

\begin{itemize}
  \item 
    <CURSOR>
\end{itemize} 

then when you enter manually \item, the line will be reindented and you get the desired indentation

\begin{itemize}
  \item 
  \item <CURSOR>
\end{itemize} 

However, if you do the same by using the UltiSnips snippet it (from honza/vim-snippets)

snippet it "Individual item" b
\item $0
endsnippet

you end up with an unintended second level indentation of the second \item:

\begin{itemize}
  \item 
    \item <CURSOR>
\end{itemize} 

Does anyone know how to resolve this?

This has already been raised on the issue tracker of UltiSnips, but I hope to find here a wider audience for this issue. BTW https://github.com/LucHermitte/mu-template claims to support reindentation.

2

You can manually fix the indent by typing CTRL-F (this is documented at :help indentkeys-format). Thus, an autonomous solution would be to issue this key-press after snippet expansion.

global !p
def fix_indent(snip):
    vim.eval('feedkeys("\<c-f>")')
endglobal

post_expand "fix_indent(snip)"
snippet it "Individual item" b
\item $0
endsnippet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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