vim-easy-align icon indicating copy to clipboard operation
vim-easy-align copied to clipboard

Auto generated range

Open kurkale6ka opened this issue 8 years ago • 0 comments

Hi,

One feature I miss coming from Tabular is the auto generated range. The idea is to call EasyAlign on a line containing our pattern and from there find all adjacent lines also containing the pattern: that is our range. For adjacent lines with our pattern there is no point running an extra vip, or gaap etc... the range can easily be calculated.

Ex: :EasyAlign/\\/ -> no range given => run it on all adjacent lines containing \

Pseudo function:

" Generate a range of lines matching a pattern
function! easy#PipeRange(includepat) range

   let top = a:firstline
   let bot = a:lastline

   " No range has been given (top == bot), thus apply range extension logic
   if a:includepat != '' && top == bot
      if top < 0 || top > line('$') || getline(top) !~ a:includepat
         return
      endif
      " Extend range upwards while we match the pattern
      while top > 1 && getline(top-1) =~ a:includepat
         let top -= 1
      endwhile
      " Extend range downwards while we match the pattern
      while bot < line('$') && getline(bot+1) =~ a:includepat
         let bot += 1
      endwhile
   endif

   let lines = map(range(top, bot), 'getline(v:val)')

endfunction

Reference: https://github.com/godlygeek/tabular/blob/master/autoload/tabular.vim#L312-L353

kurkale6ka avatar Aug 02 '17 08:08 kurkale6ka