dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README

text-objects.vim (1263B)


      1 " Adapted from https://gist.github.com/romainl/c0a8b57a36aec71a986f1120e1931f20
      2 " text objects for symbols
      3 for char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '-', '#' ]
      4     execute 'xnoremap i' . char . ' :<C-u>normal! T' . char . 'vt' . char . '<CR>'
      5     execute 'onoremap i' . char . ' :normal vi' . char . '<CR>'
      6     execute 'xnoremap a' . char . ' :<C-u>normal! F' . char . 'vf' . char . '<CR>'
      7     execute 'onoremap a' . char . ' :normal va' . char . '<CR>'
      8 endfor
      9 
     10 " Buffer text object
     11 xnoremap i& :<C-u>let z = @/\|1;/^./kz<CR>G??<CR>:let @/ = z<CR>V'z
     12 onoremap i& :<C-u>normal vi&<CR>
     13 xnoremap a& GoggV
     14 onoremap a& :<C-u>normal va&<CR>
     15 
     16 " 'Up to current line' text object
     17 vnoremap u :<C-u>silent! normal! ggV``<CR>
     18 onoremap u :normal Vu<CR>``
     19 
     20 " aliases
     21 xnoremap ir i[
     22 xnoremap ar a[
     23 
     24 " number text object (integer and float)
     25 " --------------------------------------
     26 " in
     27 function! s:VisualNumber()
     28     call search('\d\([^0-9\.]\|$\)', 'cW')
     29     normal v
     30     call search('\(^\|[^0-9\.]\d\)', 'becW')
     31 endfunction
     32 xnoremap in :<C-u>call <SID>VisualNumber()<CR>
     33 onoremap in :<C-u>normal vin<CR>
     34 
     35 " last change text object
     36 " -----------------------
     37 xnoremap ik `]o`[
     38 onoremap ik :<C-u>normal vik<CR>
     39 onoremap ak :<C-u>normal vikV<CR>
     40