Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto insert text at a newline in vim

Tags:

vim

latex

I am editing a LaTeX file with vim. When I am in the \begin{itemize} environment, is there any way to tell vim to autoinsert \item whenever I open a new line?

like image 840
Samad Lotia Avatar asked Feb 03 '26 18:02

Samad Lotia


1 Answers

function CR()
    if searchpair('\\begin{itemize}', '', '\\end{itemize}', '')
        return "\r\\item"
    endif
    return "\r"
endfunction
inoremap <expr><buffer> <CR> CR()

Put this into your .vim/ftplugins/tex.vim file (or any .vim inside .vim/ftplugins/tex directory).

like image 71
ZyX Avatar answered Feb 06 '26 13:02

ZyX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!