Browse files

add `;` object trigger to affect text object under cursor

Defines `;` to select the object currently below the cursor.
Intended for use when positioned above an opening or closing quote/bracket.
  • Loading branch information...
1 parent e8a57e7 commit 0c630e1ecb7ae25a5c6fc6dda3521cca04ad4cb1 @mislav committed Jun 20, 2013
Showing with 17 additions and 0 deletions.
  1. +17 −0 plugin/change_current_object.vim
View
17 plugin/change_current_object.vim
@@ -0,0 +1,17 @@
+" 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

0 comments on commit 0c630e1

Please sign in to comment.