forked from acornejo/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc.fzf
97 lines (88 loc) · 2.51 KB
/
vimrc.fzf
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
function! s:tag_handler(tag)
if !empty(a:tag)
let token = split(split(a:tag, '\t')[2],';"')[0]
let m = &magic
setlocal nomagic
execute token
if m
setlocal magic
endif
endif
endfunction
function! s:yank_list()
if exists(":Yanks")
redir => ys
silent Yanks
redir END
return split(ys, '\n')[1:]
else
return reverse(['0 ' . @0, '1 ' . @1, '2 ' . @2, '3 ' . @3, '4 ' . @4, '5 ' . @5, '6 ' . @6, '7 ' . @7, '8 ' . @8, '9 ' . @9])
endif
endfunction
function! s:yank_handler(reg)
if empty(a:reg)
echo "aborted register paste"
else
let token = split(a:reg, ' ')
if exists(":Yanks")
execute 'Paste' . token[0]
else
execute 'normal! "' . token[0] . 'p'
endif
endif
endfunction
function! s:ag_prompt()
call inputsave()
let pattern = substitute(@/, '\\<', '', '')
let pattern = substitute(pattern, '\\>', '', '')
let pattern = input('Ag: ',pattern)
call inputrestore()
if empty(pattern)
echo 'aborted search.'
else
let @/ = pattern
execute 'Ag' pattern
endif
endfunction
function! s:dir_handler(dir)
execute 'lcd ~/src/'.a:dir
execute 'FZF' . '~/src/'.a:dir
if has("nvim")
call feedkeys('i')
endif
endfunction
command! FZFTag if !empty(tagfiles()) | call fzf#run({
\ 'source': "sed '/^\\!/d;s/\t.*//' " . join(tagfiles()) . ' | uniq',
\ 'sink': 'tag',
\ 'options': '+m',
\ 'down': '50%'
\ }) | else | echo 'No tags' | endif
command! FZFTagFile if !empty(tagfiles()) | call fzf#run({
\ 'source': "cat " . join(tagfiles()) . ' | grep -P "' . expand('%:t') . '"',
\ 'sink': function('<sid>tag_handler'),
\ 'options': '+m --with-nth=1',
\ 'down': '50%'
\ }) | else | echo 'No tags' | endif
command! FZFYank call fzf#run({
\ 'source': <sid>yank_list(),
\ 'sink': function('<sid>yank_handler'),
\ 'options': '-m',
\ 'down': 12
\ })
command! FZFProjects call fzf#run({
\ 'source': "ls -1p ~/src | awk -F/ '/\\/$/ {print $1}'",
\ 'sink': function('<sid>dir_handler'),
\ 'options': '-m',
\ 'down': '50%'
\ })
nnoremap <silent> <Leader>t :FZFTagFile<CR>
nnoremap <silent> <Leader>T :FZFTag<CR>
nnoremap <silent> <Leader>f :Files<CR>
nnoremap <silent> <Leader>m :Marks<CR>
nnoremap <silent> <Leader>a :call <sid>ag_prompt()<CR>
nnoremap <silent> <Leader>A :Ag <C-R><C-W><CR>
nnoremap <silent> <Leader>y :FZFYank<CR>
nnoremap <silent> <Leader>b :Buffers<CR>
nnoremap <silent> <Leader>r :History<CR>
nnoremap <silent> <Leader>p :FZFProjects<CR>
nnoremap <silent> <Leader>j :BLines<CR>