Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

vim: ad hoc code completion?

23 views
Skip to first unread message

Rui Maciel

unread,
Apr 30, 2013, 5:20:16 AM4/30/13
to
Is it possible to configure vim to, say, when a user types "itemize" in
insert mode automatically insert:

\begin{itemize}
_
\end{itemize}

...being _ the cursor position?

I suspect that the imap command is the way to go, but I haven't found any
tutorial on how to use it for this purpose.


Thanks in advance,
Rui Maciel

Rui Maciel

unread,
Apr 30, 2013, 5:30:18 AM4/30/13
to
Rui Maciel wrote:

> I suspect that the imap command is the way to go, but I haven't found any
> tutorial on how to use it for this purpose.

The best that I could come up with was this:

:imap <Leader>item \begin{itemize}<enter>\end{itemize}<esc>k0o

when \item is typed in insert mode, an itemize environment is defined.

Does anyone know of a better way to pull this off?

Gary Johnson

unread,
Apr 30, 2013, 2:09:42 PM4/30/13
to
You could use an abbreviation instead of an imap, but you would have to
be careful when typing "itemize" anywhere in the document. A way around
that would be to use a shortened version or misspelling of itemize,
e.g.,

iab <buffer> itemiz \begin{itemize}<enter>\end{itemize}<esc>k0o

HTH,
Gary
0 new messages