junegunn / junegunn/vim-easy-align

Auto generated range

Open
#111 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Vim Script
Stars
4.2k
Forks
122
PR merge metrics
No merged PRs in 30d

Description

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:
```viml
" 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.