Last active
December 30, 2015 17:19
-
-
Save AndrewRadev/7860476 to your computer and use it in GitHub Desktop.
Tentative text object for latex math.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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