-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdlib.vim
More file actions
50 lines (41 loc) · 1.36 KB
/
stdlib.vim
File metadata and controls
50 lines (41 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function! s:FindAllMatches(string, pattern)
" takes a string and a pattern, returns a list of dictionaries which is of
" the format:
"
" { value, start, end }
"
" We use a needle, where once we get a match we skip the needle the length
" of the match, to avoid submatches polluting the list
let l:matches = []
let l:needle = 0
while l:needle < strlen(a:string)
let l:match = matchstr(a:string, a:pattern, l:needle)
if l:match == ''
break
endif
let l:start = match(a:string, a:pattern, l:needle)
let l:end = l:start + strlen(l:match)
call add(l:matches, {'value': l:match, 'start': l:start, 'end': l:end})
let l:needle = l:end
endwhile
return l:matches
endfunction
function! s:YankVisualSelection()
" SAVE (start)
let reg_save = @"
let visual_start_save = getpos("'<") " ? Optional ?
let visual_end_save = getpos("'>") " ? Optional ?
let paste_start_save = getpos("'[")
let paste_end_save = getpos("']")
" SAVE (end)
silent normal! yiw
let yanked_word = @"
" RESTORE (start)
let @" = reg_save
call setpos("'<", visual_start_save)
call setpos("'>", visual_end_save)
call setpos("'[", paste_start_save)
call setpos("']", paste_end_save)
" RESTORE (end)
return yanked_word
endfunction