-
Notifications
You must be signed in to change notification settings - Fork 1
/
command.vim
131 lines (125 loc) · 3.71 KB
/
command.vim
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
vim9script
import autoload "./autoload/utils.vim" as Utils
# :Reverse [[[1
command! -bar -range=% Reverse :<line1>,<line2>global/^/m <line1>-1<bar>nohl
# ChineseCount [[[1
function ChineseCount() range
let save = @z
silent exec 'normal! gv"zy'
let text = @z
let @z = save
silent exec 'normal! gv'
let cc = 0
for char in split(text, '\zs')
if char2nr(char) >= 0x2000
let cc += 1
endif
endfor
echo "Count of Chinese charasters is:"
echo cc
endfunc
vnoremap <F7> :call <SID>ChineseCount()<cr>
# :Shuffle | Shuffle selected lines [[[1
command! -range=% Shuffle :<line1>,<line2>py3 Shuffle()
# :A [[[1
command! A call ben#a('e')
command! AV call ben#a('botright vertical split')
# :PX | chmod +x [[[1
command! PX if !empty(expand('%'))
\| write
\| call system('chmod +x ' .. expand('%'))
\| silent e
\| else
\| echohl WarningMsg
\| echo 'Save the file first'
\| echohl None
\| endif
# RFC [[[1
command! -bar -count=0 RFC :e /usr/share/doc/rfc/txt/rfc<count>.txt|setl ro noma
# Paste [[[1
command! -range=% Paste :<line1>,<line2>py3 LilyPaste()
# Join [[[1
function Lilydjwg_join(sep, bang) range
if a:sep[0] == '\'
let sep = strpart(a:sep, 1)
else
let sep = a:sep
endif
let lines = getline(a:firstline, a:lastline)
if a:firstline == 1 && a:lastline == line('$')
let dellast = 1
else
let dellast = 0
endif
exe a:firstline .. ',' .. a:lastline .. 'd_'
if a:bang != '!'
call map(lines, "substitute(v:val, '^\\s\\+\\|\\s\\+$', '', 'g')")
endif
call append(a:firstline-1, join(lines, sep))
if dellast
$d_
endif
endfunction
command! -nargs=1 -range=% -bang Join :<line1>,<line2>call Lilydjwg_join(<q-args>, "<bang>")
# Quote [[[1
def Quote(quote: string, bang: string)
const q = quote == '' ? '"' : quote
const l = getline('.')
if l != '' || bang != '!'
(q .. l .. q)->setline(line('.'))
endif
enddef
command! -bang -nargs=? -range=% Quote :<line1>,<line2>call Quote(<q-args>, "<bang>")
def StrArray(line1: number, line2: number)
# StrArray [[[1
execute printf(":%s,%sQuote", line1, line2)
execute printf(":%s,%sJoin ,", line1, line2)
execute printf("normal yss]")
enddef
command! -bang -nargs=? -range=% StrArray :call StrArray(<line1>, <line2>)
# Ghq [[[1
def GhqList(A: string, ...args: list<any>): list<string>
const projs = globpath(expand('~/ghq/github.com'), '*/*', 0, 1)
->map((k, x) => substitute(x, '^.*[/\\]\ze[^/\\]*[/\\]', '', ''))
return projs->Utils.Matchfuzzy(A)
enddef
command! -nargs=1 -complete=customlist,GhqList Ghq execute 'edit ' .. expand('~/ghq/github.com/') .. <q-args>
# FollowLink [[[1
def FollowLink()
const filepath = expand('%')
if !filereadable(filepath)
return
endif
const resolved = resolve(filepath)
if resolved ==# filepath
return
endif
echom fnameescape(resolved)
# FIXME: dont affect other window
# enew
# bwipeout #
execute 'bwipeout %'
execute 'edit ' .. fnameescape(resolved)
redraw
enddef
command! -nargs=0 FollowLink call <SID>FollowLink()
# Capture [[[1
const scratchFile = $HOME .. '/tmp/scratch.txt'
def Capture()
call mkdir($HOME .. "/tmp", 'p')
Scratch
normal G
silent put +
write
enddef
command! -nargs=0 Scratch call Utils.OpenInTab(scratchFile)
command! -nargs=0 Capture call <SID>Capture()
nnoremap <silent> <leader>x :Scratch<CR>
# SetTabWidth [[[1
command! -nargs=0 SetTabWidth2 call Utils.SetTabWidth(2, true)
command! -nargs=0 SetTabWidth4 call Utils.SetTabWidth(4, true)
command! -nargs=0 SetHardTabWidth2 call Utils.SetTabWidth(2, false, 0)
command! -nargs=0 SetHardTabWidth4 call Utils.SetTabWidth(4, false, 0)
command! -nargs=0 SetHardTabWidth8 call Utils.SetTabWidth(8, false, 0)
# ]]]
# vim:fdm=marker:fmr=[[[,]]]:ft=vim