-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimperatorrc
412 lines (357 loc) · 10.3 KB
/
.vimperatorrc
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
" Treat file as vim config
" vim: set ft=vim:
map , <Leader>
" set defsearch=startpage
ignorekeys clear
ignorekeys add https://docs.google.com
ignorekeys add https://translate.google.com
ignorekeys add -except=q,<ESC>,:,g,t,e,T,Q,1,2,3,4,5,6,7,8,9,0 https://mail.google.com/
ignorekeys add -except=<C-l>,<C-h>,:,t,g,G,e,T,L,n,o,q,Q,r,i,h,l,1,2,3,4,5,6,7,8,9,0 https://duckduckgo.com/
set scroll=20
" Reload config
" map <C-r> :source /Users/john/.pentadactylrc<CR>
map <C-r> :source /Users/john/.vimperatorrc<CR>
" nmap <Leader>ds :set defsearch=startpage
" More vim like movement
nmap l <CR>
nmap L :forward<CR>
nmap i gi
" nmap i gi<C-t>i
" nmap i <Insert>
" tmap <CR> i<Cr>
nmap J 10<Down>
nmap K 10<Up>
nmap j 100<Down>
nmap k 100<Up>
" Tabs
nmap g1 b1<CR>
nmap g2 b2<CR>
nmap g3 b3<CR>
nmap g4 b4<CR>
nmap g5 b5<CR>
nmap g6 b6<CR>
nmap g7 b7<CR>
nmap g8 b8<CR>
nmap g9 b9<CR>
" Map quick marks to normal marks
nmap \' go
nmap m M
" q for quit
" nmap q :tabclose<CR>
nmap cc <M-A-k>
nmap ce <M-A-i>
" Quick history
nmap <Leader>h :history<CR>;t
" nmap l v -urls=*duckduckgo*
" Language search engine
nmap <Leader>se :t http://www.wordreference.com/esen/
nmap <Leader>es :t http://www.wordreference.com/enes/
nmap er :t https://translate.google.com/#tr/en/
nmap et :t https://translate.google.com/#en/tr/
nmap <Leader>sc :t http://www.wordreference.com/conj/ESverbs.aspx?v=
nmap <Leader>tc :t http://www.verbix.com/webverbix/go.php?Submit=Go&D1=31&H1=131&T1=
" Programming search engine
nmap <Leader>so :o http://stackoverflow.com/search?q=
" Qmarks
qmark m https://mail.google.com
qmark b http://bbc.co.uk/news
qmark g http://www.theguardian.com/uk
qmark k https://dashboard.heroku.com
qmark i https://firstlook.org/theintercept
qmark h https://news.ycombinator.com/
qmark n http://www.thenation.com/blogs/ali-gharib
qmark x http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/tmux.1?query=tmux&sec=1
qmark t https://trello.com
qmark y http://www.youtube.com
qmark f http://www.huffingtonpost.com/graham-e-fuller
qmark a https://docs.angularjs.org/api
qmark r https://www.reddit.com/r/programming
qmark p https://trello.com/b/mF1SY3dI/pocketlab-chromebook
qmark l http://localhost:3000
qmark s https://docs.google.com/a/zode64.com/spreadsheets/d/1uJyzSoF2PG2qT2yznjxrKJ0nbqiFDRggpCWxBA5-4P8
""" CSS
style stackoverflow.com,startpage.com,3g2upl4pq6kufc4m.onion,duckduckgo. :focus {background:yellow;}
" style * :focus {background:yellow !important; color:black !important;}
style * #statusbar-display {display: none !important;}
""" Javascript
js <<EOM
var ddg = "3g2upl4pq6kufc4m.onion/lite";
// var spResults = "startpage.com/do/search";
var spResults = "startpage.com";
var duckduckgo = "duckduckgo.com";
var spSearch = "startpage.com/$";
var init = function(filter, initFunction, args) {
if(matchesHref(filter)) {
initFunction(args);
}
}
var mapper = function(key, mapTo, exceptions) {
mappings.addUserMap(
[modes.NORMAL],
[key], "",
function(){
if(exceptions) {
for(var i = 0; i < exceptions.length; i++) {
if(matchesHref(exceptions[i]["filter"])) {
var m = exceptions[i]["mapTo"];
if(isFunction(m)) {
m();
}
else {
feedKeys(m);
}
return;
}
}
}
if(isFunction(mapTo)) {
mapTo();
}
else {
feedKeys(mapTo);
}
}, {}
);
};
var functionMapper = function(key, mapToFunction) {
mappings.addUserMap(
[modes.NORMAL],
[key], "",
mapToFunction, {}
);
};
var linkMapper = function(key, link, newTab) {
mappings.addUserMap(
[modes.NORMAL],
[key], "",
function(arg) {
if(newTab) {
liberator.execute("tabopen "+link);
}
else {
liberator.execute("open "+link);
}
}, {}
);
};
var isFunction = function(obj) {
return !!(obj && obj.constructor && obj.call && obj.apply);
};
var matchesHref = function(expression) {
if(isFunction(expression)) {
return expression();
}
else {
var re = new RegExp(expression);
return re.test(bWindow.location.href);
}
}
var feedKeys = function(keys) {
events.feedkeys(keys);
}
var openInNewTab = function() {
var tabIndex = getBrowser().selectedTab._tPos;
var href = bWindow.document.activeElement.getAttribute("href");
liberator.execute("tabopen "+href);
getBrowser().selectTabAtIndex(tabIndex);
}
var backInNewTab = function() {
var href = bWindow.location.href;
var tabIndex = getBrowser().selectedTab._tPos;
liberator.execute("tabopen "+href);
getBrowser().selectTabAtIndex(tabIndex);
liberator.execute("back");
}
var resultList = function(s) {
var self = this;
var _url = bWindow.location.href;
var selector = s;
var results = getResults(s);
var position = 0;
function getResults(selector) {
return bWindow.document.querySelectorAll(selector);
}
return {
next : function() {
this.reloadFocus();
// Jumps ahead and then back to make content visible
if(position < results.length-2) {
this.focus(position + 2);
this.focus(position - 1);
}
else {
this.focus(results.length - 1);
}
},
previous : function() {
// Jumps back and then forward to make content visible
this.reloadFocus();
if(position > 1) {
this.focus(position - 3);
this.focus(position + 2);
}
else {
this.focus(0);
feedKeys("<Up>");
feedKeys("<Up>");
feedKeys("<Up>");
}
},
last : function() {
this.reloadFocus();
this.focus(results.length-1);
this.focus(position-1);
},
first : function() {
this.reloadFocus();
this.focus(0);
feedKeys("<Up>");
feedKeys("<Up>");
feedKeys("<Up>");
},
forward : function() {
this.reloadFocus();
position += 7;
this.focus((position < results.length-1) ? position : results.length-1);
this.focus(position-1);
},
back : function() {
this.reloadFocus();
position -= 6;
position = (position >= 0) ? position : 0;
this.focus(position);
},
focus : function(i) {
position = i;
if(results[i]) {
results[i].focus();
}
},
reloadFocus : function() {
this.refresh();
this.focus(position);
},
atUrl : function() {
return (bWindow.location.href == this.url());
},
refresh : function() {
if(this.atUrl()) {
results = getResults(selector);
}
},
dead : function() {
try {
// try any call to results length
results.length;
return false;
}
catch(e) {
return true;
}
},
url : function() {
return _url;
}
};
}
var currentResultList = null;
var initResultList = function(selector) {
if(resultListExists()) {
currentResultList.reloadFocus();
}
else {
currentResultList = resultList(selector);
currentResultList.focus(0);
}
}
var nextResult = function() {
currentResultList.next();
// bWindow.document.activeElement.parentNode.parentNode.className += " here";
}
var previousResult = function() {
currentResultList.previous();
}
var firstResult = function() {
currentResultList.first();
}
var forwardResult = function() {
currentResultList.forward();
}
var backResult = function() {
currentResultList.back();
}
var lastResult = function() {
currentResultList.last();
}
var focusResult = function(i) {
currentResultList.focus(i);
}
var resultListExists = function() {
return (currentResultList && currentResultList.atUrl());
}
var yankFocus = function() {
var href = bWindow.document.activeElement.getAttribute("href");
}
var removeIfNotFirstTab = function() {
var numTabs = getBrowser().tabs.length;
if(numTabs > 1) {
getBrowser().removeTab(getBrowser().selectedTab);
}
}
var removeAllTabsExceptCurrent = function() {
var currentTab = getBrowser().selectedTab;
var i = getBrowser().tabs.length - 1;
while(i >= 0) {
var tab = getBrowser().tabs[i];
if(tab !== currentTab) {
getBrowser().removeTab(tab);
}
i--;
}
}
mapper("h", function() {
liberator.execute("back");
});
// mapper("j", "20<C-d>", [{filter:resultListExists, mapTo:nextResult}]);
// mapper("k", "20<C-u>", [{filter:resultListExists, mapTo:previousResult}]);
mapper("j", "10<Down>", [{filter:resultListExists, mapTo:nextResult}]);
mapper("k", "10<Up>", [{filter:resultListExists, mapTo:previousResult}]);
mapper("gg", "<Home>", [{filter:resultListExists, mapTo:firstResult}]);
mapper("G", "<End>", [{filter:resultListExists, mapTo:lastResult}]);
mapper("<C-f>", "40<C-d>", [{filter:resultListExists, mapTo:forwardResult}]);
mapper("<C-b>", "40<C-u>", [{filter:resultListExists, mapTo:backResult}]);
mapper("<C-l>", openInNewTab );
mapper("<C-h>", backInNewTab );
mapper("q", removeIfNotFirstTab );
mapper("Q", removeAllTabsExceptCurrent );
linkMapper("d", duckduckgo);
linkMapper("D", duckduckgo, true);
initAll = function() {
// init(ddg+"/", initResultList, "a.result-link");
// init(duckduckgo+"\\/\\?q=", initResultList, "a.result__a");
init("ycombinator", initResultList, "td.title > a");
init("reddit", initResultList, "div.entry > p.title > a");
init(spResults, initResultList, ".result h3 a");
init("bbc.com/news$", initResultList, "a.title-link");
// init("theguardian.com/uk", initResultList, "div.fc-item__container > a");
init("youtube.com/watch", initResultList, ".video-list-item .content-wrapper a.spf-link");
init("youtube.com/results", initResultList, ".yt-lockup-title a.spf-link");
// init("theintercept/$", initResultList, "h1 > a");
// init("mutt.org", initResultList, "li > a:last-child");
// init(spSearch, feedKeys, "i");
// init(ddg+"$", feedKeys, "i");
init("stackoverflow.com/search", initResultList, ".result-link > span > a");
}
var shouldInit = true;
initPages = function() {
bWindow = window.content.window;
bWindow.onpageshow = function(){
initAll();
}
};
EOM
""" Init
" autocmd PageLoad .* :js initPages()
autocmd LocationChange .* :js initPages()
" autocmd LocationChange .* :js modes.passAllKeys = false
" autocmd LocationChange doc\\.google\\.com js modes.passAllKeys = true