# Inserting text within a block automaticaly for each Enter button pressing?

I write LaTeX code in vim. I also installed vim-latex. When I am inside a itemize block that means inside \begin{itemize}....\end{itemize} I enter Enter and add new \item .....

If vim can detect the block and add \item command when I enter Enter inside that block it easy very helpful to and I can make same things for another block also.

I guess it may be possible in vim.

I am waiting vim's super expert(super hero).

This can be achieved very simply using the following pattern, using a conditional expression map and searchpairpos which detects the presence of an unclosed itemize environment:

function! CheckItemize()
let [l:lnum, l:cnum] = searchpairpos('\\begin{itemize}', '',
\  '\\end{itemize}', 'nbW')
return l:lnum > 0
endfunction

inoremap <expr> <cr> CheckItemize() ? '<cr><tab>\item ' : '<cr>'


inoremap <expr> <cr> CheckItemize() ? '<cr>\item ' : '<cr>'

• works, but \item shift left one tab each time. see this pasteboard.co/H90pzhR.png – alhelal Feb 23 '18 at 18:20
• How can I modify your answer so that it also works for command o? – alhelal Feb 24 '18 at 0:59