[Vim-latex-devel] splitting lines
Brought to you by:
srinathava,
tmaas
From: Carl M. <cm...@ma...> - 2002-11-09 03:20:43
|
Here is another feature which I would very much like to see. Automatic splitting of lines is a great feature for editing. On the other hand, it is a pain when an editor splits up a math expression $...$. As part of auctex.vim, I wrote the following function(s) which keep $...$ expressions on the same line, while allowing the user to keep typing without hitting <CR>. Best wishes, Carl Mueller ---------------------- " The following is necessary for TexFormatLine() and TexFill() set tw=0 " substitute text width let b:tw = 79 " With this map, <Space> will split up a long line, keeping the dollar " signs together (see the next function, TexFormatLine). inoremap <buffer> <Space> <Space><Esc>:call <SID>TexFill(b:tw)<CR>a function! s:TexFill(width) if col(".") > a:width exe "normal a##\<Esc>" call <SID>TexFormatLine(a:width) exe "normal ?##\<CR>2s\<Esc>" endif endfunction function! s:TexFormatLine(width) normal $ let length = col(".") let go = 1 while length > a:width+2 && go let between = 0 let string = strpart(getline(line(".")),0,a:width) " Count the dollar signs let evendollars = 1 let counter = 0 while counter <= a:width-1 if string[counter] == '$' && string[counter-1] != '\' " Skip \$. let evendollars = 1 - evendollars endif let counter = counter + 1 endwhile " Get ready to split the line. exe "normal " . (a:width + 1) . "|" if evendollars " Then you are not between dollars. exe "normal ?\\$\\| \<CR>W" else " Then you are between dollars. normal F$ if col(".") == 1 let go = 0 endif endif exe "normal i\<CR>\<Esc>$" let length = col(".") endwhile endfunction |