2

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).

3

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>'

Depending on your indent settings, you may use instead:

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
  • Although your solution works, but I don't understand all terms you use. If you give your code's explanation or link it is better for understanding others as well as I. – alhelal Feb 24 '18 at 0:50
  • How can I modify your answer so that it also works for command o? – alhelal Feb 24 '18 at 0:59

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.