forked from rafi/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactionmenu.vim
More file actions
95 lines (80 loc) · 2.81 KB
/
actionmenu.vim
File metadata and controls
95 lines (80 loc) · 2.81 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
" actionmenu
" ---
" Context-aware menu at your cursor
if exists('g:loaded_actionmenu') || ! has('nvim')
finish
endif
let g:loaded_actionmenu = 1
" Default icon for the actionmenu (see nerdfonts.com)
let g:actionmenu#icon = { 'character': '', 'foreground': 'yellow' }
command! -nargs=0 ActionMenu call s:actionmenu()
function! s:actionmenu()
let l:cword = expand('<cword>')
call actionmenu#open(s:build_menu(l:cword), function('s:apply_action'))
endfunction
function! s:apply_action(timer_id)
let [l:index, l:item] = g:actionmenu#selected
if ! empty(get(l:item, 'user_data'))
execute l:item['user_data']
endif
endfunction
function! s:build_menu(cword)
let l:items = []
let l:filetype = &filetype
if empty(a:cword)
" Blank operations
if l:filetype ==# 'go'
let l:items = extend(l:items, [
\ { 'word': 'If err', 'user_data': 'GoIfErr' },
\ { 'word': 'Vet', 'user_data': 'GoVet' },
\ { 'word': 'Run', 'user_data': 'GoRun' },
\ ])
endif
let l:items = extend(l:items, [
\ { 'word': 'Select all', 'user_data': 'normal! ggVG' },
\ { 'word': '-------' },
\ ])
else
" Filetype operations
if l:filetype ==# 'python'
let l:items = extend(l:items, [
\ { 'word': 'Definition', 'user_data': 'call jedi#goto()' },
\ { 'word': 'References…', 'user_data': 'call jedi#usages()' },
\ { 'word': '--------' },
\ ])
elseif l:filetype ==# 'go'
let l:items = extend(l:items, [
\ { 'word': 'Callees…', 'user_data': 'GoCallees' },
\ { 'word': 'Callers…', 'user_data': 'GoCallers' },
\ { 'word': 'Definition', 'user_data': 'GoDef' },
\ { 'word': 'Describe…', 'user_data': 'GoDescribe' },
\ { 'word': 'Implements…', 'user_data': 'GoImplements' },
\ { 'word': 'Info', 'user_data': 'GoInfo' },
\ { 'word': 'Referrers…', 'user_data': 'GoReferrers' },
\ { 'word': '--------' },
\ ])
elseif l:filetype ==# 'javascsript' || l:filetype ==# 'jsx'
let l:items = extend(l:items, [
\ { 'word': 'Definition', 'user_data': 'TernDefSplit' },
\ { 'word': 'References…', 'user_data': 'TernRefs' },
\ { 'word': '--------' },
\ ])
endif
" Word operations
let l:items = extend(l:items, [
\ { 'word': 'Find symbol…', 'user_data': 'DeniteCursorWord tag:include -no-start-filter' },
\ { 'word': 'Paste from…', 'user_data': 'Denite neoyank -default-action=replace -no-start-filter' },
\ { 'word': 'Grep…', 'user_data': 'DeniteCursorWord grep -no-start-filter' },
\ { 'word': '-------' },
\ ])
endif
" File operations
let l:items = extend(l:items, [
\ { 'word': 'Lint', 'user_data': 'Neomake' },
\ { 'word': 'Git diff', 'user_data': 'GdiffThis' },
\ { 'word': 'Unsaved diff', 'user_data': 'DiffOrig' },
\ { 'word': 'Bookmark', 'user_data': 'BookmarkToggle' },
\ ])
return l:items
endfunction
" vim: set ts=2 sw=2 tw=80 noet :