目的の選択の開始と終了 (行/列) のペアがあります。
それを実際の視覚的な選択として設定する方法は?
元:
私はバッファを持っています:
1 2
3 4
5 6
開始: 2,1
終了: 3,2
:cal SetSelection()
通話後の希望のビジュアル選択:
3 4
5 6
「SetSelection()」はどのように見えますか?
編集
回答に基づいたエラーチェックによるこれまでの最良のソリューション
"put user in visual mode and set the visual selection
"if arguments are not valid, nothing is changed, and raises an exception
":param 1:
"Visual mode to leave user in.
"must be either one of:
"- 'v' for visual (default)
"- "\<s-v>" for line visual
"- "\<c-v>" for block visual
":type 1: string
":returns: 0
":raises: bad mode argument, bad position argument
fu! SetSelection( x, y, x2, y2, ... )
let valid_mode_strings = ["v","\<s-v>","\<c-v>"]
if a:0 > 0
if index( valid_mode_strings, a:1 ) >= 0
let mode = a:1
el
th 'bad mode argument: ' . a:1 . ' valid options: ' . join( valid_mode_strings, ', ' )
en
el
let mode = 'v'
en
let oldpos = getpos('.')
if setpos( '.', [0,a:x,a:y] ) != 0
exe "norm! \<esc>"
th 'bad position argument: ' . a:x . ' ' . a:y . ' ' . a:x2 . ' ' . a:y2
en
exe 'norm! ' . mode
if setpos( '.', [0,a:x2,a:y2] ) != 0
exe "norm! \<esc>"
cal setpos( '.', oldpos )
th 'bad position argument: ' . a:x . ' ' . a:y . ' ' . a:x2 . ' ' . a:y2
en
endf