-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom.vim
78 lines (63 loc) · 2.31 KB
/
custom.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
function! Touch()
let result=system('touch '.expand("%"))
endfunction
nnoremap <c-\> :call Touch()<CR>
function! GetVisualSelection()
" Why is this not a built-in Vim script function?!
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return ''
endif
let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][column_start - 1:]
return join(lines, "\n")
endfunction
"insert path
function! Paste(value)
:call setreg('p', a:value)
:norm "ppa
endfunction
function! InsertPath()
call fzf#run({'sink': function('Paste')})
endfunction
imap <C-F> <ESC>:call InsertPath()<CR>
function! ExtractText(key, value)
return a:value['text']
endfunction
function! PasteYankStack()
let s:yankstack = map(g:Yankstack(), function('ExtractText'))
call fzf#run(fzf#wrap({'source': s:yankstack, 'sink': function('Paste')}))
endfunction
imap <C-p> <ESC>:call PasteYankStack()<CR>
nnoremap <C-p> :call PasteYankStack()<CR>
function! DeleteBuffers(ext)
let s:buffers = filter(range(1, bufnr('$')), 'buflisted(v:val) && bufname(v:val) =~ "\.'.a:ext.'$"')
if empty(s:buffers) | throw "no *.".a:ext." buffer" | endif
exe 'bd! '.join(s:buffers, ' ')
endfunction
command! -nargs=1 BD :call DeleteBuffers(<f-args>)
function! DeleteBuffersFzf()
let s:bufnumbers = filter(range(1, bufnr('$')), 'buflisted(v:val)')
let s:buffers = map(s:bufnumbers, 'bufname(v:val)')
call fzf#run(fzf#wrap({'source': s:buffers, 'options': '-m', 'sink': 'bd!'}))
endfunction
nmap <leader>bb :call DeleteBuffersFzf()<CR>
vmap <leader>bb :call DeleteBuffersFzf()<CR>
imap <leader>bb :call DeleteBuffersFzf()<CR>
function! TrimCwd(id, str)
let cwd = getcwd()
let trimed = trim(a:str)
let result = substitute(trim(a:str), cwd.'/', '', '')
return result
endfunction
function! OpenRecentFiles()
let s:files = split(execute(':oldfiles'), '\d\+:')
let s:files = filter(s:files, {idx, val -> TrimCwd(idx, v:val) != trim(v:val)})
let s:files = map(s:files, function('TrimCwd'))
let s:files = filter(s:files, {idx, val -> !empty(globpath(getcwd(),v:val))})
call fzf#run(fzf#wrap({'source': s:files, 'options': '-m', 'sink': ':e'}))
endfunction
nmap <leader>re :call OpenRecentFiles()<CR>
vmap <leader>re :call OpenRecentFiles()<CR>