Skip to content

Instantly share code, notes, and snippets.

@mislav
Last active December 17, 2015 20:39
Show Gist options
  • Save mislav/5669229 to your computer and use it in GitHub Desktop.
Save mislav/5669229 to your computer and use it in GitHub Desktop.
Defines the `;` motion to select whatever object starts below the cursor
" Defines `;` to select the object currently below the cursor.
" Intended for use when positioned above an opening or closing quote/bracket.
"
" Examples:
"
" Move to a string, change inside it: f" ci;
" Search for a bracket, delete whole object: /{ da;
onoremap a; :<c-u>call <SID>TextObjectCursorCharacter('a')<cr>
xnoremap a; :<c-u>call <SID>TextObjectCursorCharacter('a')<cr>
onoremap i; :<c-u>call <SID>TextObjectCursorCharacter('i')<cr>
xnoremap i; :<c-u>call <SID>TextObjectCursorCharacter('i')<cr>
function! s:TextObjectCursorCharacter(motion)
let char = getline('.')[col('.')-1]
exec 'normal! v' . a:motion . char
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment