From 4bb23eba41165ed7356716a9e216145b38a4c030 Mon Sep 17 00:00:00 2001 From: yan Date: Fri, 20 Jan 2012 19:21:27 -0800 Subject: [PATCH] Added steve losh next-textobject functionality. vinb to visual inside next set of parens --- README.md | 1 + vim/plugin/settings/next-textobject.vim | 29 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 vim/plugin/settings/next-textobject.vim diff --git a/README.md b/README.md index 9291ecc..828d036 100644 --- a/README.md +++ b/README.md @@ -313,6 +313,7 @@ Included vim plugins * textobj-datetime - gives you 'da' (date), 'df' (date full) and so on text objects. useable with all standard verbs * vim-textobj-entire - gives you 'e' for entire document. so vae (visual around entire document), and etc * vim-textobj-rubysymbol - gives you ':' textobj. so va: to select a ruby symbol. da: to delete a symbol..etc + * next-textobject - from Steve Losh, ability to use 'n' such as vinb (visual inside (n)ext set of parens) **Utils** diff --git a/vim/plugin/settings/next-textobject.vim b/vim/plugin/settings/next-textobject.vim new file mode 100644 index 0000000..1189a91 --- /dev/null +++ b/vim/plugin/settings/next-textobject.vim @@ -0,0 +1,29 @@ +" Stolen from Steve Losh +" https://bitbucket.org/sjl/dotfiles/src/tip/vim/.vimrc +" +" Motion for "next/last object". For example, "din(" would go to the next "()" +" pair and delete its contents. +onoremap an :call NextTextObject('a', 'f') +xnoremap an :call NextTextObject('a', 'f') +onoremap in :call NextTextObject('i', 'f') +xnoremap in :call NextTextObject('i', 'f') + +onoremap al :call NextTextObject('a', 'F') +xnoremap al :call NextTextObject('a', 'F') +onoremap il :call NextTextObject('i', 'F') +xnoremap il :call NextTextObject('i', 'F') + +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 +