Skip to content

Instantly share code, notes, and snippets.

@numToStr
Forked from romainl/pseudo-text-objects.md
Created April 21, 2021 14:58
Show Gist options
  • Save numToStr/01213cef3c2e75b0cb0b75b2616fbde6 to your computer and use it in GitHub Desktop.
Save numToStr/01213cef3c2e75b0cb0b75b2616fbde6 to your computer and use it in GitHub Desktop.

Revisions

  1. @romainl romainl renamed this gist Apr 2, 2021. 1 changed file with 14 additions and 14 deletions.
    28 changes: 14 additions & 14 deletions text-objects.vim → pseudo-text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    " 24 simple text objects
    " ----------------------
    " 24 simple pseudo-text objects
    " -----------------------------
    " i_ i. i: i, i; i| i/ i\ i* i+ i- i#
    " a_ a. a: a, a; a| a/ a\ a* a+ a- a#
    for char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '-', '#' ]
    @@ -9,16 +9,16 @@ for char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '-',
    execute 'onoremap a' . char . ' :normal va' . char . '<CR>'
    endfor

    " line text objects
    " -----------------
    " line pseudo-text objects
    " ------------------------
    " il al
    xnoremap il g_o^
    onoremap il :<C-u>normal vil<CR>
    xnoremap al $o0
    onoremap al :<C-u>normal val<CR>
    " number text object (integer and float)
    " --------------------------------------
    " number pseudo-text object (integer and float)
    " ---------------------------------------------
    " in
    function! VisualNumber()
    call search('\d\([^0-9\.]\|$\)', 'cW')
    @@ -28,32 +28,32 @@ endfunction
    xnoremap in :<C-u>call VisualNumber()<CR>
    onoremap in :<C-u>normal vin<CR>
    " buffer text objects
    " -------------------
    " buffer pseudo-text objects
    " --------------------------
    " i% a%
    xnoremap i% :<C-u>let z = @/\|1;/^./kz<CR>G??<CR>:let @/ = z<CR>V'z
    onoremap i% :<C-u>normal vi%<CR>
    xnoremap a% GoggV
    onoremap a% :<C-u>normal va%<CR>
    " square brackets text objects
    " ----------------------------
    " square brackets pseudo-text objects
    " -----------------------------------
    " ir ar
    xnoremap ir i[
    xnoremap ar a[
    onoremap ir :normal vi[<CR>
    onoremap ar :normal va[<CR>
    " block comment text objects
    " --------------------------
    " block comment pseudo-text objects
    " ---------------------------------
    " i? a?
    xnoremap a? [*o]*
    onoremap a? :<C-u>normal va?V<CR>
    xnoremap i? [*jo]*k
    onoremap i? :<C-u>normal vi?V<CR>
    " last change text object
    " -----------------------
    " last change pseudo-text objects
    " -------------------------------
    " ik ak
    xnoremap ik `]o`[
    onoremap ik :<C-u>normal vik<CR>
  2. @romainl romainl revised this gist Apr 4, 2020. No changes.
  3. @romainl romainl revised this gist Mar 30, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -41,8 +41,8 @@ onoremap a% :<C-u>normal va%<CR>
    " ir ar
    xnoremap ir i[
    xnoremap ar a[
    onoremap ir :<C-u>normal vi[<CR>
    onoremap ar :<C-u>normal va[<CR>
    onoremap ir :normal vi[<CR>
    onoremap ar :normal va[<CR>
    " block comment text objects
    " --------------------------
  4. @romainl romainl revised this gist Mar 30, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ onoremap al :<C-u>normal val<CR>
    " number text object (integer and float)
    " --------------------------------------
    " in an
    " in
    function! VisualNumber()
    call search('\d\([^0-9\.]\|$\)', 'cW')
    normal v
  5. @romainl romainl revised this gist Mar 30, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -17,8 +17,8 @@ onoremap il :<C-u>normal vil<CR>
    xnoremap al $o0
    onoremap al :<C-u>normal val<CR>
    " number text objects (integer and float)
    " ---------------------------------------
    " number text object (integer and float)
    " --------------------------------------
    " in an
    function! VisualNumber()
    call search('\d\([^0-9\.]\|$\)', 'cW')
  6. @romainl romainl revised this gist Mar 30, 2020. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -13,9 +13,9 @@ endfor
    " -----------------
    " il al
    xnoremap il g_o^
    onoremap il :normal vil<CR>
    onoremap il :<C-u>normal vil<CR>
    xnoremap al $o0
    onoremap al :normal val<CR>
    onoremap al :<C-u>normal val<CR>
    " number text objects (integer and float)
    " ---------------------------------------
    @@ -26,23 +26,23 @@ function! VisualNumber()
    call search('\(^\|[^0-9\.]\d\)', 'becW')
    endfunction
    xnoremap in :<C-u>call VisualNumber()<CR>
    onoremap in :normal vin<CR>
    onoremap in :<C-u>normal vin<CR>
    " buffer text objects
    " -------------------
    " i% a%
    xnoremap i% :<C-u>let z = @/\|1;/^./kz<CR>G??<CR>:let @/ = z<CR>V'z
    onoremap i% :normal vi%<CR>
    onoremap i% :<C-u>normal vi%<CR>
    xnoremap a% GoggV
    onoremap a% :normal va%<CR>
    onoremap a% :<C-u>normal va%<CR>
    " square brackets text objects
    " ----------------------------
    " ir ar
    xnoremap ir i[
    xnoremap ar a[
    onoremap ir :normal vi[<CR>
    onoremap ar :normal va[<CR>
    onoremap ir :<C-u>normal vi[<CR>
    onoremap ar :<C-u>normal va[<CR>
    " block comment text objects
    " --------------------------
  7. @romainl romainl revised this gist Mar 30, 2020. 1 changed file with 12 additions and 16 deletions.
    28 changes: 12 additions & 16 deletions text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    " 24 simple text-objects
    " 24 simple text objects
    " ----------------------
    " i_ i. i: i, i; i| i/ i\ i* i+ i- i#
    " a_ a. a: a, a; a| a/ a\ a* a+ a- a#
    @@ -9,15 +9,15 @@ for char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '-',
    execute 'onoremap a' . char . ' :normal va' . char . '<CR>'
    endfor

    " line text-objects
    " line text objects
    " -----------------
    " il al
    xnoremap il g_o^
    onoremap il :normal vil<CR>
    xnoremap al $o0
    onoremap al :normal val<CR>
    " number text-objects (integer and float)
    " number text objects (integer and float)
    " ---------------------------------------
    " in an
    function! VisualNumber()
    @@ -28,33 +28,29 @@ endfunction
    xnoremap in :<C-u>call VisualNumber()<CR>
    onoremap in :normal vin<CR>
    " buffer text-objects
    " buffer text objects
    " -------------------
    " i% a%
    xnoremap i% :<C-u>let z = @/\|1;/^./kz<CR>G??<CR>:let @/ = z<CR>V'z
    onoremap i% :normal vi%<CR>
    xnoremap a% GoggV
    onoremap a% :normal va%<CR>
    " comment text-objects
    " --------------------
    " i? a?
    xnoremap <buffer> i? ?/\*<CR>o/\*\/<CR>
    onoremap <buffer> i? :normal vi?<CR>
    " square brackets text-objects
    " square brackets text objects
    " ----------------------------
    " ir ar
    xnoremap ir i[
    xnoremap ar a[
    onoremap ir :normal vi[<CR>
    onoremap ar :normal va[<CR>
    " block comment text object
    " -------------------------
    " a?
    xnoremap a? ?<C-r>=split(&commentstring, "%s")[0]<CR><CR>o/<C-r>=split(&commentstring, "%s")[1]<CR>/e<CR>
    onoremap a? :<C-u>normal va?<CR>
    " block comment text objects
    " --------------------------
    " i? a?
    xnoremap a? [*o]*
    onoremap a? :<C-u>normal va?V<CR>
    xnoremap i? [*jo]*k
    onoremap i? :<C-u>normal vi?V<CR>
    " last change text object
    " -----------------------
  8. @romainl romainl revised this gist Mar 14, 2020. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -54,4 +54,11 @@ onoremap ar :normal va[<CR>
    " -------------------------
    " a?
    xnoremap a? ?<C-r>=split(&commentstring, "%s")[0]<CR><CR>o/<C-r>=split(&commentstring, "%s")[1]<CR>/e<CR>
    onoremap a? :<C-u>normal va?<CR>
    onoremap a? :<C-u>normal va?<CR>
    " last change text object
    " -----------------------
    " ik ak
    xnoremap ik `]o`[
    onoremap ik :<C-u>normal vik<CR>
    onoremap ak :<C-u>normal vikV<CR>
  9. @romainl romainl revised this gist Feb 29, 2020. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -48,4 +48,10 @@ onoremap <buffer> i? :normal vi?<CR>
    xnoremap ir i[
    xnoremap ar a[
    onoremap ir :normal vi[<CR>
    onoremap ar :normal va[<CR>
    onoremap ar :normal va[<CR>
    " block comment text object
    " -------------------------
    " a?
    xnoremap a? ?<C-r>=split(&commentstring, "%s")[0]<CR><CR>o/<C-r>=split(&commentstring, "%s")[1]<CR>/e<CR>
    onoremap a? :<C-u>normal va?<CR>
  10. @romainl romainl revised this gist Jul 14, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -45,5 +45,7 @@ onoremap <buffer> i? :normal vi?<CR>
    " square brackets text-objects
    " ----------------------------
    " ir ar
    xnoremap ir i[
    xnoremap ar a[
    onoremap ir :normal vi[<CR>
    onoremap ar :normal va[<CR>
  11. @romainl romainl revised this gist Jun 29, 2019. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -41,3 +41,9 @@ onoremap a% :normal va%<CR>
    " i? a?
    xnoremap <buffer> i? ?/\*<CR>o/\*\/<CR>
    onoremap <buffer> i? :normal vi?<CR>
    " square brackets text-objects
    " ----------------------------
    " ir ar
    onoremap ir :normal vi[<CR>
    onoremap ar :normal va[<CR>
  12. @romainl romainl revised this gist Jan 17, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ onoremap in :normal vin<CR>
    xnoremap i% :<C-u>let z = @/\|1;/^./kz<CR>G??<CR>:let @/ = z<CR>V'z
    onoremap i% :normal vi%<CR>
    xnoremap a% GoggV
    onoremap a% :normal vi%<CR>
    onoremap a% :normal va%<CR>
    " comment text-objects
    " --------------------
  13. @romainl romainl revised this gist May 26, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -21,9 +21,9 @@ onoremap al :normal val<CR>
    " ---------------------------------------
    " in an
    function! VisualNumber()
    call search('\d\([^0-9\.]\|$\)', 'cW')
    normal v
    call search('\(^\|[^0-9\.]\d\)', 'becW')
    call search('\d\([^0-9\.]\|$\)', 'cW')
    normal v
    call search('\(^\|[^0-9\.]\d\)', 'becW')
    endfunction
    xnoremap in :<C-u>call VisualNumber()<CR>
    onoremap in :normal vin<CR>
  14. @romainl romainl revised this gist May 26, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    " 26 simple text-objects
    " 24 simple text-objects
    " ----------------------
    " i_ i. i: i, i; i| i/ i\ i* i+ i- i#
    " a_ a. a: a, a; a| a/ a\ a* a+ a- a#
  15. @romainl romainl revised this gist May 26, 2017. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ onoremap il :normal vil<CR>
    xnoremap al $o0
    onoremap al :normal val<CR>
    " number (integer and float) text-objects
    " number text-objects (integer and float)
    " ---------------------------------------
    " in an
    function! VisualNumber()
    @@ -28,10 +28,16 @@ endfunction
    xnoremap in :<C-u>call VisualNumber()<CR>
    onoremap in :normal vin<CR>
    " buffer text-object
    " ------------------
    " buffer text-objects
    " -------------------
    " i% a%
    xnoremap i% :<C-u>let z = @/\|1;/^./kz<CR>G??<CR>:let @/ = z<CR>V'z
    onoremap i% :normal vi%<CR>
    xnoremap a% GoggV
    onoremap a% :normal vi%<CR>
    " comment text-objects
    " --------------------
    " i? a?
    xnoremap <buffer> i? ?/\*<CR>o/\*\/<CR>
    onoremap <buffer> i? :normal vi?<CR>
  16. @romainl romainl revised this gist May 26, 2017. 1 changed file with 33 additions and 2 deletions.
    35 changes: 33 additions & 2 deletions text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,37 @@
    for char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '%', '-', '#' ]
    " 26 simple text-objects
    " ----------------------
    " i_ i. i: i, i; i| i/ i\ i* i+ i- i#
    " a_ a. a: a, a; a| a/ a\ a* a+ a- a#
    for char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '-', '#' ]
    execute 'xnoremap i' . char . ' :<C-u>normal! T' . char . 'vt' . char . '<CR>'
    execute 'onoremap i' . char . ' :normal vi' . char . '<CR>'
    execute 'xnoremap a' . char . ' :<C-u>normal! F' . char . 'vf' . char . '<CR>'
    execute 'onoremap a' . char . ' :normal va' . char . '<CR>'
    endfor
    endfor

    " line text-objects
    " -----------------
    " il al
    xnoremap il g_o^
    onoremap il :normal vil<CR>
    xnoremap al $o0
    onoremap al :normal val<CR>
    " number (integer and float) text-objects
    " ---------------------------------------
    " in an
    function! VisualNumber()
    call search('\d\([^0-9\.]\|$\)', 'cW')
    normal v
    call search('\(^\|[^0-9\.]\d\)', 'becW')
    endfunction
    xnoremap in :<C-u>call VisualNumber()<CR>
    onoremap in :normal vin<CR>
    " buffer text-object
    " ------------------
    " i% a%
    xnoremap i% :<C-u>let z = @/\|1;/^./kz<CR>G??<CR>:let @/ = z<CR>V'z
    onoremap i% :normal vi%<CR>
    xnoremap a% GoggV
    onoremap a% :normal vi%<CR>
  17. @romainl romainl created this gist May 26, 2017.
    6 changes: 6 additions & 0 deletions text-objects.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    for char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '%', '-', '#' ]
    execute 'xnoremap i' . char . ' :<C-u>normal! T' . char . 'vt' . char . '<CR>'
    execute 'onoremap i' . char . ' :normal vi' . char . '<CR>'
    execute 'xnoremap a' . char . ' :<C-u>normal! F' . char . 'vf' . char . '<CR>'
    execute 'onoremap a' . char . ' :normal va' . char . '<CR>'
    endfor