-
Notifications
You must be signed in to change notification settings - Fork 33
/
vimperatorrc
395 lines (338 loc) · 15.7 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
"2.3.1 (created: 2010/04/07 18:25:13)
" delete any previously defined autocommands in this context
autocmd!
" `mapleader` setting/option is removed!
map , <Leader>
set urlseparator='\|'
" set guioptions+=N
set gui=nomenu,tabs,navigation
" Currently broken.
" set tabnumbers
set! browser.dom.window.dump.enabled=true
set! devtools.errorconsole.enabled=true
" do not activate middle- or ctrl-clicked links
set activate-=links
" search shortcuts (without completion)
command! -nargs=* gg open google <args>
map s :gg<Space>
map S :tab gg<Space>
" bypass ctrl-tab (ref: http://code.google.com/p/dactyl/issues/detail?id=171)
" NOTE: only required for Pentadactyl
" nmap <C-Tab> <Pass>
" nmap <C-S-Tab> <Pass>
nnoremap <A-,> <C-S-Tab>
nnoremap <A-.> <C-Tab>
" command to clear history
" command! clearhist sanitize commandline
" Esc: abort request
noremap <Esc> <C-c><Esc>
noremap <F1> :tab<Space>:help<Space>
" prev/next for german keyboard layout
nnoremap <silent> ö [[
nnoremap <silent> ä ]]
" next/prev as single word is rather weak!
" group prevnext
au LocationChange .* set previouspattern='^voriges Angebot$',^<$,^<(?!<),[^<]<$,'^(prev|previous|früher|zurück|Vorherige)$','(vorige Seite|next page)',^(<<|«|‹)$,^«,«$,^‹,'\b(prev|previous|zurück)\b'
au LocationChange .* set nextpattern='^nächstes Angebot$',^>$,^>(?!>),[^>]>$,'^(next|more|weiter|später)$','(nächste Seite|next page)',^(>>|»|›)$,^»,»$,›$,'\b(next|more|weiter|vor(wärts)?)\b'
au LocationChange www.xing.com set previouspattern=^Zurück$ nextpattern=^Weiter$
" TODO test
au LocationChange www.xda-developers.com set previouspattern='^newer entries$' nextpattern='^older entries$'
" heise.de: start page and comments
au LocationChange www.heise.de set previouspattern='^Neuere$',^<<$ nextpattern='^Ältere$',^>>$
" forum.xda-developers.com
au LocationChange ://[^]+/showthread\.php\? set previouspattern='^<$'
au LocationChange ://[^]+/showthread\.php\? set nextpattern='^>$'
" group default
set popups=tab,resized
" A builtin bit.ly shortener.
" Based on http://github.com/scy/dotscy/commit/4526f23a09b2ae51fb7f4b1e2ed3aec84f318fa5
javascript <<EOF
function shortenURLBitLy (url) {
var req = new XMLHttpRequest();
req.open("GET", "http://api.bit.ly/v3/shorten?login=blueyed&apiKey=R_a405dd06737e888ca6971b295b0b7a13&format=txt&longUrl=" + encodeURIComponent(url), true)
req.onreadystatechange = function (ev) {
if (req.readyState == 4) {
if (req.status == 200) {
util.copyToClipboard(req.responseText.replace(/\s+$/, ''), true);
} else {
liberator.echo(req.responseText);
}
}
}
req.send(null);
}
EOF
" mnemonic: Go and yank.
map <silent> gy :js shortenURLBitLy(buffer.URL)<cr>
" Toggle hosts / urls: handle special cases, and fallback to appending or
" removing '.localdomain' suffix.
" This is meant to easily switch between local/development and live
" environment.
javascript <<EOF
function parseQueryString() {
var qd = {};
content.location.search.substr(1).split("&").forEach(function(item) {
var s = item.split("="),
k = s[0],
v = s[1] && decodeURIComponent(s[1]);
(k in qd) ? qd[k].push(v) : qd[k] = [v]
})
return qd
}
function toggleHosts() {
// NOTE: <John-Galt> blueyed: let uri = buffer.uri.clone(); uri.host = whatever; uri.spec
// first check custom maps of hostnames to toggle
let cb_handle_q_arg = function(url, lhs, rhs) {
// return url.replace(lhs, rhs).replace(/[&?](?!q=[&?])*/, '');
let qd = parseQueryString();
return url.replace(lhs, rhs).replace(/[&?].*/, '?q=' + qd["q"]);
}
let customtoggle = {
'de.wikipedia.org': 'en.wikipedia.org',
'en.wikipedia.org': 'de.wikipedia.org',
// Toggle between DuckDuckGo and Googgle.
// map 'https://duckduckgo.com/?q=foo+bar'
// to 'https://www.google.com/search?q=foo+bar'
'://duckduckgo.com/': {'rhs': '://www.google.com/search', 'cb': cb_handle_q_arg},
'://www.google.com/search': {'rhs': '://duckduckgo.com/', 'cb': cb_handle_q_arg},
'://www.google.de/search': {'rhs': '://duckduckgo.com/', 'cb': cb_handle_q_arg},
}
let curhost = content.location.host;
let cururl = buffer.URL;
console.log(curhost);
for( var lhs in customtoggle ) {
let rhs = customtoggle[lhs];
if( cururl.indexOf(lhs) != -1 ) {
if( typeof(rhs) == 'string' ) {
return String.replace(cururl, lhs, rhs);
}
return rhs.cb(cururl, lhs, rhs.rhs);
}
}
// Fallthrough: prepend/remove suffix.
let suffix = '.localdomain';
if( curhost.indexOf(suffix, curhost.length - suffix.length) !== -1 ) {
return String.replace(cururl, suffix, '');
}
// Append/inject suffix.
return String.replace(cururl, /(\.\w{2,4})([\/:])/, "$1"+suffix+"$2");
}
EOF
map gz :js liberator.open(toggleHosts())<cr>
" Firefox Sync: connect+sync on startup, sync on exit (does not appear to work)
" NOTE: gets triggered when opening a new window, too. With some Sync UI again in the status bar, this is not necessary anymore.
"autocmd VimperatorEnter .* emenu Tools.Sync.Connect
"autocmd VimperatorEnter .* emenu Tools.Sync.Sync Now
"autocmd VimperatorLeavePre .* emenu Tools.Sync.Sync Now
" Setup colors(cheme)
" colorscheme solarized-light
colorscheme solarized
" Pimp colors/layout
hi -append Hint font-size:10px !important;font-weight:normal !important;background:#fff !important;border:1px solid red !important;color:#000 !important;font-family:"DejaVu Sans Mono", monospace !important; padding:1px 3px !important;
" hi -append StatusLine background-color:#ddd !important; color:#000 !important; border-bottom:1px solid #666 !important; border-top:1px solid #666 !important
"
" " Make the "Find hit TOP, continuing at BOTTOM" more prominent
" hi StatusWarningMsg -append background-color:blue ! important; color:white ! important;
"
"
" TODO: see TabVisited extension: https://bugzilla.mozilla.org/show_bug.cgi?id=487242
" style -name blueyedchrome chrome://* <<EOM
" tab.tabbrowser-tab[selected="true"] { font-size:1.2em !important; font-weight:bold !important; color:#000 !important }
"
" /* http://kb.mozillazine.org/User:Dickvl */
" .tabbrowser-tab[unread="true"] .tab-text {}
" .tabbrowser-tab:not([unread="true"]) .tab-text {}
" .tabbrowser-tab[selected="true"] .tab-text {}
" EOM
set errorbells visualbell
" rss-icon in statusbar, via http://code.google.com/p/vimperator-labs/issues/detail?id=237
javascript <<EOF
(function(){
if ( ! document.getElementById("BMB_subscribeToPageMenuitem").disabled ) {
var feedButton = document.getElementById("BMB_subscribeToPageMenupopup");
// var feedButton = document.createElement("")
// <image xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="lazarus-statusbarpanel-image" src="chrome://lazarus/skin/lazarus.png" onclick="Lazarus.onStatusbarImageClick(event)" tooltip="lazarus-statusbaricon-tooltip-enabled"/>
var feedPanel = document.createElement("statusbarpanel");
feedPanel.setAttribute("id", "feed-panel-clone");
feedPanel.appendChild(feedButton);
feedPanel.firstChild.setAttribute("style", "padding: 0; max-height: 16px;");
document.getElementById("status-bar")
.appendChild(feedPanel);
// .insertBefore(feedPanel, document.getElementById("security-button"));
}
})();
EOF
" reddit tips (via http://www.reddit.com/r/vim/comments/crs9u/some_vimperator_tips_for_redditors/)
" open current page with reddit toolbar (allows submitting)
nmap e :js liberator.open("http://reddit.com/submit?url=" + encodeURIComponent(buffer.URL))<cr>
" add bookmark for subreddits (":o r")
"bma -k=r http://reddit.com/r/%s/
" focus content frame (workaround for FF4?!)
" XXX: content.wrappedJSObject.frames["inner_toolbar"] ...
"autocmd PageLoad ^http://www.reddit.com/tb/.* js content.window.frames[1].window.frames[1].focus()
" Does not work for pages that use Javascript to focus an input box, e.g.
" Groupon.
set focuscontent
" command to replace all image links with the actual image (most useful with post-a-picture threads)
" based on some snippet from reddit, but adopted for Vimperator; add allFrames and maxHeight handling
command! inlineimages js (function($) {orig$=$; $.each(buffer.allFrames, function(){win=this.wrappedJSObject; $=function(sel){return orig$(sel, win.document)} ; win.document.ondragstart=function(){return false};dst=function(e){return (p=Math.pow)(p(e.clientX-(rc=e.target.getBoundingClientRect()).left,2)+p(e.clientY-rc.top,2),.5)};$("[href~=imgur]").not($(t="[href$=jpeg],[href$=gif],[href$=png],[href$=jpg]")).each(function(){this.href+='.jpg'});void($(t).not(".EGraw").attr({'class':'EGraw',target:'blank'}).each(function(){$(this).append($('<span />').toggle(function(e){$(this).html(' [-]').next().show();return false},function(e){$(this).html(' [+]').next().hide();return false}).click()).append($('<img>').attr({src:this.href,style:'display:block;max-width:500px;max-height:500px',title:'Drag to resize'}).mousedown(function(e){(t=this.wrappedJSObject).iw=t.width;t.d=dst(e);t.dr=false;t.style.maxHeight="none";e.preventDefault();}).mousemove(function(e){if((t=this.wrappedJSObject).d){t.style.maxWidth=t.style.width=((dst(e))*t.iw/t.d)+"px";t.dr=true}}).mouseout(f=function(e){(t=this.wrappedJSObject).d=false;if(t.dr)return false}).click(f))}))})})(content.wrappedJSObject.$ || $);
" search leo.org in a new tab
map <Leader>l :to http://dict.leo.org/ende?lp=ende&search=
" Open current location via Coral CDN
" String.replace is a workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=633830
map gp :js liberator.open( String.replace(buffer.URL, /(\.\w{2,4})\//, "$1.nyud.net/") )<cr>
" NoScript popup
map <Leader>n :noscript popup<cr>
" Toggle pocket sidebar
nmap <Leader>p :emenu View.Sidebar.Pocket<cr>
" Quickmarks (for `go` and `gn`)
silent qmark 0 hahler.de
silent qmark a https://www.google.com/contacts
silent qmark c https://www.google.com/calendar
silent qmark f https://facebook.com
silent qmark g https://groups.google.com/forum/#!myforums
silent qmark h https://heise.de
silent qmark m https://mail.google.com/mail
silent qmark n https://www.google.de/reader/view | www.reddit.com | https://twitter.com
silent qmark p https://www.producteev.com/dashboard.php
silent qmark r https://reddit.com
silent qmark t https://twitter.com
silent qmark z https://github.com/notifications
" Use buffer.URL for yanking (encoded spaces).
" (not required for Pentadactyl, see http://code.google.com/p/vimperator-labs/issues/detail?id=797).
js <<EOM
mappings.addUserMap([modes.NORMAL], ["y"], "Yank current location to the clipboard",
function(){
util.copyToClipboard(buffer.URL, true);
});
EOM
" Setup `editor` option dynamically. {{{1
" OBSOLETE: setup editor via LocationChange autocmd. {{{2
" " group! editor
" " js my_editor=(config.OS.isMacOSX ? 'mvim' : 'gvim') + ' -f -c "set ft={0} | call cursor(<line>, <column>)"'
" " NOTE: no support for "<column>" and "<line"> with Vimperator: http://code.google.com/p/vimperator-labs/issues/detail?id=875
" " js my_editor='gvim' + ' -f -c "set ft={0} | call cursor(<line>, <column>)"'
" js my_editor='gvim' + ' -f -c "set ft={0}"'
" autocmd -js LocationChange .* options.editor=my_editor.replace('{0}', 'html spell')
" autocmd -js LocationChange (www\.reddit\.com|github\.com|stackoverflow\.com)/ options.editor=my_editor.replace('{0}', 'markdown spell')
" autocmd -js LocationChange ^https?://mail\\..* options.editor=my_editor.replace('{0}', 'mail spell')
" autocmd -js LocationChange ^https?://[^/]+/phpmyadmin/ options.editor=my_editor.replace('{0}', 'html')
" autocmd -js LocationChange ^https?://.*trac.*/wiki/ options.editor=my_editor.replace('{0}', 'tracwiki')
" " group default
" }}}2
" Initially done via autocmd (see above), then rewritten based on [1] and adopted for Vimperator.
" 1: http://ingo-karkat.de/blog/2012/05/22/Pentadactyl%20set%20filetype%20in%20external%20Vim%20editor%20based%20on%20URL.html
set editor='vim-in-term'
javascript <<EOF
// Get options for `editor`.
// These get used with `set ` prepended and passed to `editor` via `-c`.
function editExternallyGetOptions() {
// return 'spell | echom "foo"';
// These differ between Pentadactyl and Vimperator.
var host = content.location.host;
var path = content.location.pathname;
// alert(host, path);
switch(host.replace(/^www\./, "")) {
case "github.com":
if (! path.match("/wiki/"))
return "ft=markdown spell";
// TODO: handle /wiki
case "reddit.com":
case "stackoverflow.com":
return "ft=markdown spell";
}
if (host.match(/^mail\./))
return 'ft=mail spell';
if (host.match(/.*\.wikia\.com$/) || host.match(/.*\.wikipedia\.org$/))
return "ft=mediawiki spell";
if (path.match(/\/phpmyadmin\//))
return 'ft=html spell';
if (host == 'code.djangoproject.com')
return 'ft=tracwiki';
if (buffer.URL.match(/^https?:\/\/.*trac.*\/wiki\//))
return 'sw=4 ft=tracwiki';
return 'spell';
}
function editExternallyWithOptions() {
var edopts = editExternallyGetOptions();
var save_editor = options["editor"];
options["editor"] = options["editor"] + ' -c "set ' + edopts.replace(/"/g, '\\"') + '"';
// alert(options['editor']);
editor.editFieldExternally();
options["editor"] = save_editor;
}
// Overwrite Ctrl-I input mapping.
mappings.addUserMap([modes.INSERT], ["<c-i>"], "Launch the external editor.", editExternallyWithOptions);
// Alternative mapping in case <C-i> is taken, e.g. in reddit/stackoverflow comments.
mappings.addUserMap([modes.INSERT], ["<f4>"], "Launch the external editor.", editExternallyWithOptions);
EOF
" }}}1
" Bypassing keys. {{{1
javascript <<EOF
function myPassAllKeys(buffer) {
if( /(groups|mail|plus|docs)\.google\.[a-z]+\//.test(buffer.URL) ) {
return true;
}
return false;
}
EOF
autocmd LocationChange .* js modes.passAllKeys = myPassAllKeys(buffer)
" }}}1
" use homerow for hintkeys; see also https://code.google.com/p/dactyl/issues/detail?id=167
" set hintchars=asdfgöälkjh
" add suggestion,history to completion list
" set complete=search,location,file,suggestion
" set complete=slfbhSt
" NOTE: removed "f" (local files), might spin up diskstation (via autofs)
" set complete=slfSt
set complete=slSt
" center_select plugin: https://code.google.com/p/vimperator-labs/issues/detail?id=221
nnoremap <silent> zz :centerselect<CR>
"nnoremap <silent> zz :centerselect "border: 5px solid orange;"<CR>
"nnoremap <silent> n n:norm zz<CR>
"nnoremap <silent> N N:norm zz<CR>
nnoremap zH 10h
nnoremap zL 10l
nnoremap j 5j
nnoremap k 5k
nnoremap l 5l
nnoremap h 5h
" Use Ctrl-d/u instead?!
nnoremap J 20j
nnoremap K 20k
nnoremap <silent> zt :topselect<CR>
nnoremap <silent> zb :bottomselect<CR>
nnoremap <silent> zc :removeselect<CR>
nnoremap h H
nnoremap l L
" tab-options plugin:
"set tabclose=opener,previous,left,right
" Focus largest frame. This replaces the auto-focus-frame.js plugin. Props @John-Galt!
au PageLoad .* -js function area(w) w.innerWidth * w.innerHeight; buffer.allFrames(doc.defaultView.top).reduce(function (w, acc) area(w) > area(acc) ? w : acc).focus()
nnoremap <leader>c :js buffer.openContextMenu()<cr>
" Yank document.title.
nnoremap <leader>yt :js util.copyToClipboard(content.document.title, true)<cr>
" Yank 'Issue #X: title (URL)' from Github issue page.
javascript <<EOF
function myCopyGithubIssueTitle(buffer) {
// return buffer.title.replace(/foo/, '$1');
let pat = /^(.*) · (Issue #\d+) · \w+\/\w+$/;
if( ! pat.test(buffer.title) ) {
liberator.echoerr("buffer title does not match.");
return;
}
let s = buffer.title.replace(pat, '$2: $1') + ' ('+buffer.URL+')';
util.copyToClipboard(s, true);
}
EOF
nnoremap <leader>yl :js myCopyGithubIssueTitle(buffer)<cr>
" remap for smooth scrolling
map j <Down>
map k <Up>
" Edit ~/.vimperatorrc in global gvim server instance.
map <leader>ec :silent !vim-in-term ~/.dotfiles/vimperatorrc &<cr>
" Toggle colorscheme.
au ColorScheme .* -javascript curtheme = args.name
map <leader>sc :execute "colorscheme " + ((typeof(curtheme) !== 'undefined' && curtheme == "solarized_light") ? "solarized_dark" : "solarized_light" )<cr>
source! ~/.vimperatorrc.local
" vim: set ft=pentadactyl.vim fdm=marker: