68 lines
1.7 KiB
VimL
68 lines
1.7 KiB
VimL
function! text_obj#URL() abort
|
|
if match(&runtimepath, 'vim-highlighturl') != -1
|
|
let url_pattern = highlighturl#default_pattern()
|
|
else
|
|
let url_pattern = expand('<cfile>')
|
|
if len(url_pattern) <= 10
|
|
return
|
|
endif
|
|
endif
|
|
|
|
" Find all URLs on the line and determine if the cursor is on one of them
|
|
let line_text = getline('.')
|
|
let url_infos = []
|
|
|
|
let [_url, _idx_start, _idx_end] = matchstrpos(line_text, url_pattern)
|
|
while _url !=# ''
|
|
let url_infos += [[_url, _idx_start+1, _idx_end]]
|
|
let [_url, _idx_start, _idx_end] = matchstrpos(line_text, url_pattern, _idx_end)
|
|
endwhile
|
|
|
|
if len(url_infos) == 0
|
|
return
|
|
endif
|
|
|
|
let [start_col, end_col] = [-1, -1]
|
|
let [buf_num, cur_row, cur_col] = getcurpos()[0:2]
|
|
for url_info in url_infos
|
|
let [_url, _idx_start, _idx_end] = url_info
|
|
if cur_col >= _idx_start && cur_col <= _idx_end
|
|
let start_col = _idx_start
|
|
let end_col = _idx_end
|
|
break
|
|
endif
|
|
endfor
|
|
|
|
if start_col == -1
|
|
return
|
|
endif
|
|
|
|
call setpos("'<", [buf_num, cur_row, start_col, 0])
|
|
call setpos("'>", [buf_num, cur_row, end_col, 0])
|
|
normal! gv
|
|
endfunction
|
|
|
|
function! text_obj#MdCodeBlock(type) abort
|
|
normal! $
|
|
let start_row = searchpos('\s*```', 'bnW')[0]
|
|
let end_row = searchpos('\s*```', 'nW')[0]
|
|
|
|
let buf_num = bufnr()
|
|
if a:type ==# 'i'
|
|
let start_row += 1
|
|
let end_row -= 1
|
|
endif
|
|
|
|
call setpos("'<", [buf_num, start_row, 1, 0])
|
|
call setpos("'>", [buf_num, end_row, 1, 0])
|
|
execute 'normal! `<V`>'
|
|
endfunction
|
|
|
|
function! text_obj#Buffer() abort
|
|
let buf_num = bufnr()
|
|
|
|
call setpos("'<", [buf_num, 1, 1, 0])
|
|
call setpos("'>", [buf_num, line('$'), 1, 0])
|
|
execute 'normal! `<V`>'
|
|
endfunction
|