Skip to content

Instantly share code, notes, and snippets.

@sjl
Forked from AndrewRadev/LICENSE
Created August 25, 2011 19:43
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sjl/1171642 to your computer and use it in GitHub Desktop.
Save sjl/1171642 to your computer and use it in GitHub Desktop.
Execute a vim motion on the "next" text object
" Motion for "next/last object". For example, "din(" would go to the next "()" pair
" and delete its contents.
onoremap an :<c-u>call <SID>NextTextObject('a', 'f')<cr>
xnoremap an :<c-u>call <SID>NextTextObject('a', 'f')<cr>
onoremap in :<c-u>call <SID>NextTextObject('i', 'f')<cr>
xnoremap in :<c-u>call <SID>NextTextObject('i', 'f')<cr>
onoremap al :<c-u>call <SID>NextTextObject('a', 'F')<cr>
xnoremap al :<c-u>call <SID>NextTextObject('a', 'F')<cr>
onoremap il :<c-u>call <SID>NextTextObject('i', 'F')<cr>
xnoremap il :<c-u>call <SID>NextTextObject('i', 'F')<cr>
function! s:NextTextObject(motion, dir)
let c = nr2char(getchar())
if c ==# "b"
let c = "("
elseif c ==# "B"
let c = "{"
elseif c ==# "d"
let c = "["
endif
exe "normal! ".a:dir.c."v".a:motion.c
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment