Re: [Vim-latex-devel] Function: Tex_InsertItem
Brought to you by:
srinathava,
tmaas
From: Mikolaj M. <mi...@wp...> - 2003-10-10 07:18:01
|
Dnia Thursday 09 of October 2003 16:17, Johannes Tanzler napisał: > > the following function inserts "\item", "\item[]", or "\item{}[]" > depending on the environment the cursor currently is in. > There are two mappings: <M-RET> starts a new line before inserting, > "<Leader>it" inserts the item in the current line. Thanks. I changed it little to better fit into lS: " Tex_InsertItem: insert item into a list {{{ " Description: Find last \begin line, extract env name, return to the start " position and insert proper \item, depending on env name. " Env names are stored in g: variables it can be used by " package files. let g:Tex_ItemNormal = ',itemize,enumerate,theindex,' let g:Tex_ItemBib = ',thebibliography,' let g:Tex_ItemDescription = ',description,' function! Tex_InsertItem() " Get current environment: let pos = line('.').' | normal! '.virtcol('.').'|' let env_line = search('^[^%]*\\begin{', 'bW') let env = matchstr(getline(env_line), '\\begin{\zs.\{-}\ze}') exe pos if g:Tex_ItemNormal =~ ','.env.',' return IMAP_PutTextWithMovement("\\item ") elseif g:Tex_ItemDescription =~ ','.env.',' return IMAP_PutTextWithMovement("\\item[<+label+>] <++>") elseif g:Tex_ItemBib =~ ','.env.',' return IMAP_PutTextWithMovement("\\item[<+biblabel+>]{<+bibkey+>}<+ +>") else return '' endif endfunction inoremap <C-CR> <ESC>o<C-R>=Tex_InsertItem()<CR> inoremap <Leader>it <C-R>=Tex_InsertItem()<CR> There are still problems: 1. Changed map from <M-CR> to <C-CR>. There are numerous difficulties with M maps but Ctrl doesn't work in terminal Vim. Any ideas? 1a. <Leader>it is rather uncommon form for lS Insert mode. Maybe ITE? 2. Solved thing with quoted begin but it doesn't recognize \%. Such construction should be extremely rare but if any regexp guru is reading advice would be appreciated :) m. |