def visual_range(pl, segment_info, CTRL_V_text='{rows} x {vcols}', v_text_oneline='C:{vcols}', v_text_multiline='L:{rows}', V_text='L:{rows}'):
'''Return the current visual selection range.
:param str CTRL_V_text:
Text to display when in block visual or select mode.
:param str v_text_oneline:
Text to display when in charaterwise visual or select mode, assuming
selection occupies only one line.
:param str v_text_multiline:
Text to display when in charaterwise visual or select mode, assuming
selection occupies more then one line.
:param str V_text:
Text to display when in linewise visual or select mode.
All texts are format strings which are passed the following parameters:
========= =============================================================
Parameter Description
========= =============================================================
sline Line number of the first line of the selection
eline Line number of the last line of the selection
scol Column number of the first character of the selection
ecol Column number of the last character of the selection
svcol Virtual column number of the first character of the selection
secol Virtual column number of the last character of the selection
rows Number of lines in the selection
cols Number of columns in the selection
vcols Number of virtual columns in the selection
========= =============================================================
'''
sline, scol, soff = [int(v) for v in vim_funcs['getpos']('v')[1:]]
eline, ecol, eoff = [int(v) for v in vim_funcs['getpos']('.')[1:]]
svcol = vim_funcs['virtcol']([sline, scol, soff])
evcol = vim_funcs['virtcol']([eline, ecol, eoff])
rows = abs(eline - sline) + 1
cols = abs(ecol - scol) + 1
vcols = abs(evcol - svcol) + 1
return {
'^': CTRL_V_text,
's': v_text_oneline if rows == 1 else v_text_multiline,
'S': V_text,
'v': v_text_oneline if rows == 1 else v_text_multiline,
'V': V_text,
}.get(segment_info['mode'][0], '').format(
sline=sline, eline=eline,
scol=scol, ecol=ecol,
svcol=svcol, evcol=evcol,
rows=rows, cols=cols, vcols=vcols,
)
评论列表
文章目录