One can create non-rectangular Visual-Block selections using C-v$
on files with lines of non-equal length.
Is it possible to programmatically determine whether the last Visual Block selection was non-rectangular?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityA little crude but this works...
func! IsDollarBlock()
let l:mode = char2nr(visualmode(""))
if l:mode != 22
echom char2nr(l:mode) . " is not block mode"
return 0
endif
sil norm! gv"aygv$"by
return @a == @b
endfunc
You can test with...
:echo IsDollarBlock()
(Assuming visual selection was not active)...first this checks whether the last visual selection was even block mode. If not it returns 0 (false). Otherwise it re-selects the visual selection and yanks into register "a", re-selects it again, issues $
and yanks into register "b". Then it compares the two registers and returns the comparison result (0/false or 1/true).
If you wanted to preserve the visual selection you could issue <Esc>
or equivalent at the beginning of the function then put norm! gv
as last command of the function.
len(uniq(sort(map(lines, strlen)))) != 1
$
and the question is specifically about creating selections with $
.