-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathkeys.vim
More file actions
175 lines (141 loc) · 5.2 KB
/
Copy pathkeys.vim
File metadata and controls
175 lines (141 loc) · 5.2 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
let s:config = ctrlspace#context#Configuration()
let s:modes = ctrlspace#modes#Modes()
let s:keyNames = []
let s:keyMap = {}
let s:characters = {}
let s:keyEscSequence = 0
function! ctrlspace#keys#KeyNames() abort
return s:keyNames
endfunction
function! ctrlspace#keys#CharacterClasses() abort
return s:characters
endfunction
function! ctrlspace#keys#KeyMap() abort
return s:keyMap
endfunction
function! ctrlspace#keys#MarkKeyEscSequence() abort
let s:keyEscSequence = 1
endfunction
function! ctrlspace#keys#Init() abort
call s:initKeyNames()
call s:initKeyMap()
call ctrlspace#keys#common#Init()
call ctrlspace#keys#help#Init()
call ctrlspace#keys#nop#Init()
call ctrlspace#keys#search#Init()
call ctrlspace#keys#buffer#Init()
call ctrlspace#keys#file#Init()
call ctrlspace#keys#tab#Init()
call ctrlspace#keys#workspace#Init()
call ctrlspace#keys#bookmark#Init()
call s:initCustomMappings()
call ctrlspace#keys#nop#DbmdexInit()
endfunction
function! s:initCustomMappings() abort
for m in ["Search", "Help", "Nop", "Buffer", "File", "Tab", "Workspace", "Bookmark"]
if has_key(s:config.Keys, m)
for [k, fn] in items(s:config.Keys[m])
" normalize synomymous keynames Enter, Return and CR all to CR
let k = (k ==? 'return' || k ==? 'enter' ? 'CR' : k)
call ctrlspace#keys#AddMapping(fn, m, [k])
endfor
endif
endfor
endfunction
function! s:initKeyNames() abort
let lowercase = "q w e r t y u i o p a s d f g h j k l z x c v b n m"
let uppercase = toupper(lowercase)
let controlList = []
for l in split(lowercase, " ")
call add(controlList, "C-" . l)
endfor
call add(controlList, "C-^")
call add(controlList, "C-]")
let controls = join(controlList, " ")
let numbers = "1 2 3 4 5 6 7 8 9 0"
let punctuation = "; : , . < > [ ] { } ( ) ' ` ~ + - _ = ! @ # $ % ^ & * / \ " .
\ '"'
let specials = "Space CR BS Tab S-Tab / ? C-f C-b C-u C-d C-h C-w " .
\ "Bar BSlash MouseDown MouseUp LeftDrag LeftRelease 2-LeftMouse " .
\ "Down Up Home End Left Right PageUp PageDown " .
\ "F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12"
if !s:config.UseMouseAndArrowsInTerm || has("gui_running")
let specials .= " Esc"
endif
let specials .= (has("gui_running") || has("win32")) ? " C-Space" : " Nul"
let keyNames = split(join([lowercase, uppercase, controls, numbers, punctuation, specials], " "), " ")
" won't work with leader mappings
if ctrlspace#keys#IsDefaultKey()
for i in range(len(keyNames))
let fullKeyName = (strlen(keyNames[i]) > 1) ? ("<" . keyNames[i] . ">") : keyNames[i]
if fullKeyName ==# ctrlspace#keys#DefaultKey()
call remove(keyNames, i)
break
endif
endfor
endif
let s:keyNames = keyNames
let s:characters.lowercase = split(lowercase, " ")
let s:characters.uppercase = split(uppercase, " ")
let s:characters.controls = split(controls, " ")
let s:characters.numbers = split(numbers, " ")
let s:characters.punctuation = split(punctuation, " ")
let s:characters.specials = split(specials, " ")
endfunction
function! ctrlspace#keys#Undefined(k) abort
call ctrlspace#ui#Msg("Key '" . a:k . "' doesn't work in this view.")
endfunction
function! s:initKeyMap() abort
let Undefined = function("ctrlspace#keys#Undefined")
let blankMap = {}
for k in s:keyNames
let blankMap[k] = Undefined
endfor
for m in ["Search", "Help", "Nop", "Buffer", "File", "Tab", "Workspace", "Bookmark"]
let s:keyMap[m] = copy(blankMap)
endfor
endfunction
function! ctrlspace#keys#AddMapping(funcName, mapName, keys) abort
let keys = []
for entry in a:keys
if has_key(s:characters, entry)
call extend(keys, s:characters[entry])
else
call add(keys, entry)
endif
call ctrlspace#help#AddMapping(a:funcName, a:mapName, entry)
endfor
let FuncRef = function(a:funcName)
for k in keys
let s:keyMap[a:mapName][k] = FuncRef
endfor
endfunction
function! ctrlspace#keys#Keypressed(key) abort
let key = (s:keyEscSequence && (a:key ==# "Z")) ? "S-Tab" : a:key
let s:keyEscSequence = 0
if s:modes.Help.Enabled
let mapName = "Help"
elseif s:modes.Search.Enabled
let mapName = "Search"
elseif s:modes.Nop.Enabled
let mapName = "Nop"
else
let mapName = ctrlspace#modes#CurrentListView().Name
endif
call s:keyMap[mapName][key](key)
endfunction
function! ctrlspace#keys#SetDefaultMapping(key, action) abort
let s:defaultKey = a:key
if !empty(s:defaultKey)
if s:defaultKey ==? "<C-Space>" && !has("gui_running") && !has("win32")
let s:defaultKey = "<Nul>"
endif
silent! exe 'nnoremap <unique><silent>' . s:defaultKey . ' ' . a:action
endif
endfunction
function! ctrlspace#keys#IsDefaultKey() abort
return exists("s:defaultKey")
endfunction
function! ctrlspace#keys#DefaultKey() abort
return s:defaultKey
endfunction