vim Part 6 [sc](★0)
-
- 616
- 2017/10/20(金) 00:35:41.26
-
>>610
矩形選択した2行の同列の文字列同士を交換するならこんなんでどうか
function! s:SwapLine()
let pos1=getpos("'<")
let pos2=getpos("'>")
let l1=pos1[1]
let c_start=pos1[2]
let l2=pos2[1]
let c_end=pos2[2]
let len=c_end - c_start + 1
let text1=strpart(getline(l1),c_start-1,len)
let text2=strpart(getline(l2),c_start-1,len)
let line1=getline(l1)
let line2=getline(l2)
let newline1=strpart(line1,0,c_start-1).text2.strpart(line1,c_end)
let newline2=strpart(line2,0,c_start-1).text1.strpart(line2,c_end)
call setline(l1,newline1)
call setline(l2,newline2)
endfunction
vmap <C-S> :<C-U>call s:SwapLine()<CR>
このページを共有する