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?
views:
192answers:
5
+1
A:
I know noting about latex but I think it is a good idea to search in vim scripts
use the search button up left :D
for example search for
latex auto completion
ali
2010-03-30 19:08:40
A:
I would recommend http://vim-latex.sourceforge.net. This package defines several maps useful for latex.
In particular for inserting \item you press <ATL-I>
skeept
2010-03-30 19:51:14
Thanks, this worked great. Although I may be pushing the envelope a little bit, is there any way where `\item` is added whenever a new line is opened automatically without having to rely on alt-I?
Samad Lotia
2010-03-30 20:27:14
In vim-latex, you can say `EIT` to start an `itemize` environment. vim-latex provides other shortcuts too.
Alok
2010-03-31 09:14:48
+1
A:
I can hit Cntl-I and it'll put it in for me in either normal mode or insert mode. This is what I put in my .vimrc:
:imap <C-i> \item
:nmap <C-i> o\item
Note that there is a space at the end of \item
.
Samad Lotia
2010-03-30 20:35:05
+1
A:
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).
ZyX
2010-03-31 09:12:33
A:
I hacked the script ZyX supplied and came up with this. It adds support for the o
and O
commands. It does not require LaTeX-VIM.
function AddItem()
if searchpair('\\begin{itemize}', '', '\\end{itemize}', '')
return "\\item "
else
return ""
endif
endfunction
inoremap <expr><buffer> <CR> "\r".AddItem()
nnoremap <expr><buffer> o "o".AddItem()
nnoremap <expr><buffer> O "O".AddItem()
Samad Lotia
2010-03-31 16:42:45