# Trigger reindentation after snippet has expanded to word in 'indentkeys'

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. ## 1 Answer 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

• Thanks for that ! Though, we need to add this post_expand "fix_indent(snip)" to every snippet we want to fix the indent. Wouldn't it be nice to fix indent for every snippet when autoindent is on ? UltiSnips doesn't seems to be able to do that. – perelo Sep 14 '20 at 16:17