Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev
Last active December 30, 2015 17:19
Show Gist options
  • Save AndrewRadev/7860476 to your computer and use it in GitHub Desktop.
Save AndrewRadev/7860476 to your computer and use it in GitHub Desktop.
Tentative text object for latex math.
onoremap <buffer> a$ :<c-u>call <SID>LatexTextObject('a')<cr>
xnoremap <buffer> a$ :<c-u>call <SID>LatexTextObject('a')<cr>
onoremap <buffer> i$ :<c-u>call <SID>LatexTextObject('i')<cr>
xnoremap <buffer> i$ :<c-u>call <SID>LatexTextObject('i')<cr>
function! s:LatexTextObject(mode)
if a:mode == 'i'
call search('\$\{1,2}', 'Wbce')
call search('\S', 'W')
normal! my
call search('\$\{1,2}', 'W')
call search('\S', 'Wb')
normal! mz
else " a:mode == 'a'
call search('\$\{1,2}', 'Wbc')
normal! my
" move away from the start match
call search('\$\{1,2}', 'Wce')
" go to the end match
call search('\$\{1,2}', 'We')
normal! mz
endif
normal! `yv`z
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment