-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimFun.vim
More file actions
executable file
·83 lines (65 loc) · 2.11 KB
/
vimFun.vim
File metadata and controls
executable file
·83 lines (65 loc) · 2.11 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
" import functions with `source file.vim`
" incurments 2 digit functions nubmers by amount
function! IncTwoDigFun(start, end, amount)
let l:funNum = a:end
let l:cursorPos = winsaveview()
" save cursor to position
while l:funNum >= a:start
let l:nextNum = l:funNum + a:amount
if l:funNum > 9
let l:subStr = 'un'.l:funNum
else
let l:subStr = 'un0'.l:funNum
endif
if l:nextNum > 9
let l:repStr = 'un'.l:nextNum
else
let l:repStr = 'un0'.l:nextNum
endif
let l:lineNum = 1
" not very efficent, but best way to do search and
" replace when using variables
" for hardcoding you can use `%s/sub/replace/g`
for l:lineStr in getline(1,"$")
call setline(l:lineNum, substitute(l:lineStr, l:subStr, l:repStr, "g"))
let l:lineNum = l:lineNum + 1
endfor
let l:funNum = l:funNum - 1
endwhile
call winrestview(l:cursorPos)
" move cursor back to orignal position
endfunction
" incurments 3 digit functions nubmers by amount
function! IncThreeDigFun(start, end, amount)
let l:funNum = a:end
let l:cursorPos = winsaveview()
" save cursor to position
while l:funNum >= a:start
let l:nextNum = l:funNum + a:amount
if l:funNum > 99
let l:subStr = 'un'.l:funNum
elseif l:funNum > 9
let l:subStr = 'un0'.l:funNum
else
let l:subStr = 'un00'.l:funNum
endif
if l:nextNum > 99
let l:repStr = 'un'.l:nextNum
elseif l:nextNum > 9
let l:repStr = 'un0'.l:nextNum
else
let l:repStr = 'un00'.l:nextNum
endif
let l:lineNum = 1
" not very efficent, but best way to do search and
" replace when using variables
" for hardcoding you can use `%s/sub/replace/g`
for l:lineStr in getline(1,"$")
call setline(l:lineNum, substitute(l:lineStr, l:subStr, l:repStr, "g"))
let l:lineNum = l:lineNum + 1
endfor
let l:funNum = l:funNum - 1
endwhile
call winrestview(l:cursorPos)
" move cursor back to orignal position
endfunction