-
Notifications
You must be signed in to change notification settings - Fork 33
/
pentadactylrc
318 lines (264 loc) · 12.4 KB
/
pentadactylrc
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
"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 guioptions+=T
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>
nmap s :gg<Space>
vmap s :gg<Space>
" bypass ctrl-tab (ref: http://code.google.com/p/dactyl/issues/detail?id=171)
nmap <C-Tab> <Pass>
nmap <C-S-Tab> <Pass>
" New tab. C-t is "Execute the next [count] mappings in a new tab.".
nmap <C-t><C-t> :tabnew<cr>
" <C-l>: Redraw and select location bar.
map -builtin <c-l> :redraw<cr><C-v><c-l>
" command to clear history
" command! clearhist sanitize commandline
" Esc: abort request
map -builtin <Esc> <C-c><Esc>
map -builtin <F1> :tab<Space>:help<Space>
" prev/next for german keyboard layout
nmap -s -b ö [[
nmap -s -b ä ]]
" 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) {
dactyl.clipboardWrite(req.responseText.replace(/\s+$/, ''), true);
} else {
dactyl.echo(req.responseText);
}
}
}
req.send(null);
}
EOF
" mnemonic: Go and yank.
map -silent gy -js shortenURLBitLy(buffer.URL)
" Toggle hostname: append or remove '.localdomain' suffix
" This is meant to easily switch between local/development and live
" environment.
javascript <<EOF
function toggleDevLiveHost() {
// NOTE: <John-Galt> blueyed: let uri = buffer.uri.clone(); uri.host = whatever; uri.spec
// first check custom maps of hostnames to toggle
let customtoggle = {
'www.betterplace.org': 'www.bp42.com',
}
let curhost = buffer.URL.host;
let cururl = buffer.URL;
for( var i in customtoggle ) {
if( curhost === i ) {
return String.replace(cururl, i, customtoggle[i]);
}
if( curhost === customtoggle[i] ) {
return String.replace(cururl, customtoggle[i], i);
}
}
// then prepend/remove suffix
let suffix = '.localdomain';
if( curhost.indexOf(suffix, curhost.length - suffix.length) !== -1 ) {
return String.replace(cururl, suffix, '');
}
// append suffix
return String.replace(cururl, /(\.\w{2,4})([\/:])/, "$1"+suffix+"$2");
}
EOF
map gz -js dactyl.open(toggleDevLiveHost());
" 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
" 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 dactyl.open("http://reddit.com/submit?url=" + encodeURIComponent(buffer.URL))
" 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()
" 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 dactyl.open( String.replace(buffer.URL, /(\.\w{2,4})\//, "$1.nyud.net/") )
" NoScript popup
map <Leader>n -ex noscript popup
" Toggle pocket sidebar
nmap <Leader>p -ex emenu View.Sidebar.Pocket
" Quickmarks (for `go` and `gn`)
silent qmark 0 hahler.de
silent qmark c http://www.google.com/calendar
silent qmark f facebook.com
silent qmark g https://groups.google.com/forum/#!myforums
silent qmark h 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 reddit.com
silent qmark t twitter.com
" 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='gvim -f'
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 = buffer.URL.host;
var path = buffer.URL.path;
// 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 (buffer.URL.match(/^https?:\/\/.*trac.*\/wiki\//))
return '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;
}
EOF
" Overwrite Ctrl-I input mapping.
imap <C-i> -js editExternallyWithOptions();
" }}}1
" Bypassing keys. {{{1
autocmd LocationChange '^https?://(groups|mail|plus|www)\.google\.com/' :normal! <C-z>
" Passthrough certain keys only, see "h key-sequence" for a list.
" set passkeys+='https://mail\.':<Left><Right><Up><Down><Del>
" }}}1
" use homerow for hintkeys; see also https://code.google.com/p/dactyl/issues/detail?id=167
set hintkeys=asdfgöälkjh
" add suggestion,history to completion list
" default: search,location,file
set complete=location,suggestion,search,file
" center_select plugin: https://code.google.com/p/vimperator-labs/issues/detail?id=221
nmap -builtin -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>
nmap -builtin zH 10h
nmap -builtin zL 10l
nmap -builtin j 5j
nmap -builtin k 5k
nmap -builtin l 5l
nmap -builtin h 5h
nmap -builtin -silent zt :topselect<CR>
nmap -builtin -silent zb :bottomselect<CR>
nmap -builtin -silent zc :removeselect<CR>
"loadplugins
" 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()
map -builtin -js <leader>c buffer.openContextMenu()
" Yank document.title.
map -builtin -js <leader>yt dactyl.clipboardWrite(content.document.title, true)
" 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) ) {
dactyl.echoerr("buffer title does not match.");
return;
}
let s = buffer.title.replace(pat, '$2: $1') + ' ('+buffer.URL+')';
dactyl.clipboardWrite(s, true);
}
EOF
map -builtin -js <leader>yl myCopyGithubIssueTitle(buffer)
map -builtin j 5j
map -builtin k 5k
" Edit ~/.vimperatorrc in global gvim server instance.
map <leader>ec :silent !gv ~/.dotfiles/pentadactylrc<cr>
source! ~/.pentadactylrc.local
" vim: set ft=pentadactyl.vim fdm=marker: