forked from odedniv/.vim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelperfuncs.vim
More file actions
417 lines (368 loc) · 9.23 KB
/
helperfuncs.vim
File metadata and controls
417 lines (368 loc) · 9.23 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
function! ConvHex()
let x=input('enter num:')
exe "py3 print(hex(".x ."))"
endfunction
function! ToggleVerbose()
if !&verbose
:!rm ~/.vim/verbose.log
:!touch ~/.vim/verbose.log
set verbosefile=~/.vim/verbose.log
set verbose=15
else
set verbose=0
set verbosefile=
endif
endfunction
function! DebugIt(interval)
for i in range(1,line('$'), a:interval)
exe ":" . i
exe "normal! Oecho 'In ' . line('.')\<CR>"
endfor
endfunction
function! GetVisualSelection() abort
let [lineSelection, colSelection] = getpos('v')[1:2]
let [lineCursor, colCursor] = getpos('.')[1:2]
" Swap line numbers if selection starts at cursor
let [lineStart, lineEnd] = (lineSelection <= lineCursor) ? [lineSelection, lineCursor] : [lineCursor, lineSelection]
let lines = getline(lineStart, lineEnd)
let mode = mode()
if mode is# "\<C-v>"
let mode = 'v'
if lineStart < lineEnd
echoerr 'block-wise selection unsupported, assuming character-wise selection'
endif
endif
if mode is# 'v'
" Swap column numbers if selection starts at cursor
let [colStart, colEnd] = (colSelection <= colCursor) ? [colSelection, colCursor] : [colCursor, colSelection]
let lines[-1] = lines[-1][:colEnd - (&selection is# 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][colStart - 1:]
endif
" if mode is# 'V'
if &l:fileformat is# 'dos'
let ending = "\<CR>\<NL>"
elseif &l:fileformat is# 'mac'
let ending = "\<CR>"
else " if is# 'unix'
let ending = "\<NL>"
endif
return join(lines, ending)
endfunction
function! CloseAllBuffersButCurrent()
%bd
e#
endfunction
"Closes the other buffers but Nerdtree. Unless only 2 buffers left. In this
"case, closes nerdtree.
function! CloseAllWindowsButCurrent()
let tabnr= tabpagenr()
let tabinfo=gettabinfo(tabnr)
let windows=tabinfo[0]['windows']
let last2=(len(windows)==2)
for winid in windows
let curwin=winnr() "could change
let winnr=win_id2win(winid)
let ft= getbufvar(winbufnr(winnr), '&filetype')
if and(winnr!=curwin,or((ft!~'netranger'),last2))
execute ':'.winnr.'close!'
endif
endfor
endfunction
function! CloseAllNR()
let tabnr= tabpagenr()
let tabinfo=gettabinfo(tabnr)
let windows=tabinfo[0]['windows']
let last2=(len(windows)==2)
for winid in windows
let curwin=winnr() "could change
let winnr=win_id2win(winid)
let ft= getbufvar(winbufnr(winnr), '&filetype')
if (ft=~'netranger')
execute ':'.winnr.'q!'
endif
endfor
endfunction
function! Goprev()
exec 'redir @x | silent ls | redir END'
if match(@x,'"\[Location List\]"') >= 0
lprev
elseif match(@x,'"\[Quickfix List\]"') >= 0
cprev
else
exec 'echo "Neither Location or Quicklist found!"'
endif
endfunction
function! Gonext()
exec 'redir @x | silent ls | redir END'
if match(@x,'"\[Location List\]"') >= 0
lnext
elseif match(@x,'"\[Quickfix List\]"') >= 0
cnext
else
"exec 'echo "Neither Location or Quicklist found!"'
copen
endif
endfunction
"executes command, return lines as string
function! MinExec(cmd)
redir => tmp
exec printf('silent %s',a:cmd)
redir END
return tmp
endfunction
"Remaps repeat pairs
function! RepRemap(mapA,mapB)
let varA=maparg(a:mapA,'n')
let varB=maparg(a:mapB,'n')
execute "nmap <expr> " . a:mapA . " repmo#Key('".varA ."', '". varB. "')"
execute "nmap <expr> " . a:mapB . " repmo#Key('".varB ."', '". varA. "')"
endfunction
"executes command , opens in new tab all the lines. useful in cases of :map
function! Exec(cmd)
redir @x
exec printf('silent %s',a:cmd)
redir END
tabnew
norm "xp
endfunction
function! PInsert2(item)
let @z=a:item
norm "zp
call feedkeys('a')
endfunction
function! PInsert(item)
let @z=a:item
norm "zp
endfunction
function! ExportC()
python << EOF
x=vim.eval("@x").replace('\n','').replace(" ","")
if len(x)%2!=0:
print 'bad x'
else:
st='unsigned char bytes[] ={'
st+=','.join(['0x'+x[i:i+2] for i in xrange(0,len(x),2)])
st+='};'
vim.command("let sInVim = '%s'"% st)
vim.command("let @+=sInVim")
EOF
endfunction
function! Search()
:M @x
endfunction
function! HandleCJ()
let func=input('type cmd to execute (calls execute funct). @x is match')
echo "\<CR>"
execute func
endfunction
function! HandleCH()
let func=input('type cmd to eval vim command (@x is arg)/ExportC()/Search())')
echo "\<CR>"
echo eval(func)
endfunction
function! HandleH()
let func=input('Enter python to execute(match is the input): ')
echo "\<CR>"
let retInVim=RunPython(@x,func)
return retInVim
endfunction
function! HandleCF()
let func=input('Enter "cmd" to eval vim cmd(@x is arg): ')
" echo "\<CR>"
return eval(func)
endfunction
function! HandleF()
let func=input("Enter python to eval(match is the input,@x is arg): ")
" echo "\<CR>"
let retInVim=RunPython2(@x,func)
return retInVim
endfunction
function! CopyPath()
let @+=expand('%:p')
endfunction
function! DisableKeys()
noremap <Up> <Nop>
noremap <Down> <Nop>
noremap <Left> <Nop>
noremap <Right> <Nop>
endfunction
"make new file
function! Ff()
exe 'norm "zy'
:echo @z
endfunction
function! GetMappings()
let lines=MinExec('map')
let lines=split(lines,'\n')
return lines
endfunction
function! GetCommands()
let lines=[]
let nu=histnr("cmd")
for i in range(1,nu)
let lines+=[histget("cmd",i)]
endfor
return lines
endfunction
function! CdDir(item)
:exe "cd ".a:item
endfunction
function! HandleCommand(item)
call feedkeys("zq:")
call feedkeys("G?\\V".escape(a:item,'\/?')."\<CR>",'n')
endfunction
function! BH(item)
exe ":T " . a:item
endfunction
function! Wolfram()
:g/Out\[/d
:%s/In\[.*\]:=//g
endfunction
function! MakeItFaster(adv)
if (a:adv)
:let g:airline_extensions = []
:CocDisable
:ALEDisable
:NoMatchParen
:autocmd! InsertLeave *
:autocmd! TextYankPost *
":syntax disable
"augroup fugitive
"autocmd! BufWriteCmd *
"autocmd! FileWriteCmd *
"augroup END
endif
":GitGutterDisable
"autocmd! BufReadPre //*
":Fugitive?
":autocmd! BufWritePre *
":autocmd! BufWritePost *
":autocmd! BufWrite *
endfunction
"to replace multiple lines in another windows copy to reg first
function! Dorep()
let aa=split(getreg('c'),'\n')
for k in aa
exe "g/".k."/norm I\/\/U"
endfor
endfunction
if g:on_ek_computer
source ~/vimpy3/secfunc.vim
endif
function! ReplaceRPC()
%s/\[.\{-}in.\{-}\]//g
%s/\[.\{-}out.\{-}\]//g
endfunction
function! MakeJson(...)
if a:0 > 0
let override = a:1
else
let override = 0
end
PY << EOF
import os
import json
uu=(not os.path.exists('.vimspector.json')) or vim.eval('override')
if uu==1:
print('making')
dir=vim.eval('expand("%:h")')
prog= vim.eval('expand("%:p")')
name= vim.eval('expand("%:t")').replace('.py','')
data={
"configurations": {
"genhash: Launch": {
"adapter": "debugpy",
"configuration": {
"name": name+": Launch",
"type": "python",
"request": "launch",
"python": "/Users/ekarni/.pyenv/versions/3.8.5/bin/python3" ,
"cwd": dir,
"stopOnEntry": "true",
"console": "externalTerminal",
"debugOptions": [],
"justMyCode":"true",
"program": prog,
"args":[],
#"env" :
# {"PYTHONPATH":"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/"}
}
}
}
}
with open('.vimspector.json', 'w') as outfile:
json.dump(data, outfile,sort_keys=True,indent=4, separators=(',', ': '))
else:
print('already exists')
EOF
endfunction
function! MakeJson2(...)
if a:0 > 0
let override = a:1
else
let override = 0
end
PY << EOF
import os
import json
uu=(not os.path.exists('.vimspector.json')) or vim.eval('override')
if uu==1:
print('making')
dir=vim.eval('expand("%:h")')
prog= vim.eval('expand("%:p")')
name= vim.eval('expand("%:t")').replace('.py','')
data={
"configurations": {
"genhash: Launch": {
"adapter": "debugpy",
"configuration": {
"name": name+": Launch",
"type": "python",
"request": "launch",
"python": "/Users/ekarni/.pyenv/versions/2.7.18/bin/python2.7" ,
"cwd": dir,
"stopOnEntry": "true",
"console": "externalTerminal",
"debugOptions": [],
"justMyCode":"true",
"program": prog,
"args":[],
#"env" :
# {"PYTHONPATH":"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/"}
}
}
}
}
with open('.vimspector.json', 'w') as outfile:
json.dump(data, outfile,sort_keys=True,indent=4, separators=(',', ': '))
else:
print('already exists')
EOF
endfunction
function! SSHAgent()
:!eval "$(ssh-agent -s)"
:!ssh-add
endfunction
"function! STab_Or_Complete()
"if mode(1)=='ic'||mode(1)=='ix'
"return "\<C-P>"
"else
"return "\<S-Tab>"
"endif
"endfunction
"function! Tab_Or_Complete()
"if mode(1)=='ic'||mode(1)=='ix'
"return "\<C-N>"
"else
"return "\<Tab>"
"endif
"endfunction
func! ToggleHebrew()
if &rl
set norl
set keymap=
else
set rl
set keymap=hebrew
end
endfunc