bairui

Vim Latex Dollar Text Objects

Nov 19th, 2011
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 0.79 KB | None | 0 0
  1. " latex $text-objects$
  2.  
  3. function! s:ADollar()
  4.   if search('\m\%#\$', 'bcnW')
  5. " On $
  6.     if search('\m\_.\+\$', 'nW')
  7.       return "/\\$\<CR>"
  8.     elseif search('\m\$\_.\+\%#', 'bnW')
  9.       return "?\\$\<CR>"
  10.     else
  11.       return "\<C-\>\<C-n>\<Esc>"
  12.     endif
  13.   elseif search('\m\$\%(\%(\$\)\@!\_.\)*\%#\_.\{-}\%(\$\)', 'bcnW')
  14. " Between $ and $
  15.     return "?\\$\<CR>o/\\$\<CR>"
  16.   endif
  17. " Return to normal mode and sound a bell.
  18.   return "\<C-\>\<C-n>\<Esc>"
  19. endfunction
  20.  
  21. function! s:IDollar()
  22.   let vad = s:ADollar()
  23.   if vad !~ '\m[\x1b]' " If the result contains an <Esc>, not in a dollar
  24.     return vad . 'owoge'
  25.   endif
  26.   return vad
  27. endfunction
  28.  
  29. vnoremap <expr> a$ <SID>ADollar()
  30. vnoremap <expr> i$ <SID>IDollar()
  31. onoremap a$ :normal va$<CR>
  32. onoremap i$ :normal vi$<CR>
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment