Skip to content

Instantly share code, notes, and snippets.

@kshenoy
Forked from sjl/next_motion_mapping.vim
Last active December 12, 2015 02:28
Show Gist options
  • Save kshenoy/4698889 to your computer and use it in GitHub Desktop.
Save kshenoy/4698889 to your computer and use it in GitHub Desktop.
" Motion for "next/last object".
" For example, 'din(' will go to the Next '()' pair and delete its contents.
" and 'dip(' will go to the Previous '()' 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 ap :<c-u>call <SID>NextTextObject('a', 'F')<cr>
xnoremap ap :<c-u>call <SID>NextTextObject('a', 'F')<cr>
onoremap ip :<c-u>call <SID>NextTextObject('i', 'F')<cr>
xnoremap ip :<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