-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimperatorrc
586 lines (447 loc) · 15.8 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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
" 2.0 (created: 2008/08/16 18:51:52)
"---------------------------------------------------------------------------------------------
" Global variables
"---------------------------------------------------------------------------------------------
let mapleader = ","
" For the sake of char-hint-mode2.js; use lower-case letter for identifing links.
let hintsio = 'io'
" for char-hint-mode2.js
let g:hintlabeling="a"
"---------------------------------------------------------------------------------------------
" Mappings
"---------------------------------------------------------------------------------------------
" open addon configuration page in new tab
noremap <Leader>a <Esc>:tabnew<CR>:addon<CR>
"close all tabs
noremap <Leader>q :qa<CR>
noremap <Leader>x :xa<CR>
" create a new tab is just 2 key stroke!
noremap <Leader>t :tabopen<CR><CR>
" Show metainfo for current page
noremap <Leader>i g<C-g>
" Save curent page
noremap <Leader>s :sav
" restart firefox quickly
noremap <Leader>r :restart<CR>
" make tab-switching more easy
noremap h gT
noremap l gt
noremap < g0
noremap > g$
" swap these two key-bindings, since open homepage in new tab is used more oftenlly.
noremap gh gH
noremap gH gh
" scroll more
noremap j 3j
noremap k 3k
noremap J <C-d>
noremap K <C-u>
" Noscript mapping
noremap <Leader>ni :noscript info<CR>
noremap <Leader>no :noscript popup<CR>
noremap <Leader>nt :noscript toggletemp<CR>
noremap <Leader>np :noscript toggleperm<CR>
" 's' map to :search proviede by plugin
noremap s :search<Space>
" 'S' stands for 'Stop'
noremap S <C-c>
" Access Ubiquity features!
noremap <Leader>u :ubiquity<Space>
" Go to the website's root point
noremap U gU<CR>
" 'V' stands for 'View Source Code'
noremap V gf
" since : is more often used than ;
noremap ; :
" re-enable ctrl-l to move focus on location bar
noremap <C-l> <C-v><C-l>
" disbale highlight for the moment
" Note, in order to map '\',we have to escape it with itself...:(
" So, '\' won't work, '\\' is required here.
noremap <Silent> \\ :nohlsearch<CR>
" go up quickly
noremap <BS> gu
noremap <S-Up> gu
" switch focus between frames
noremap { [f
noremap } ]f
" prev/next is more easy now!
noremap [ [[
noremap ] ]]
" open/close the delicious sidbar
noremap <C-b> <C-z><C-b><Esc>
inoremap <C-b> <C-z><C-b><Esc>
" add current page to delicious
noremap <C-y> <C-z><C-y><Esc>
inoremap <C-y> <C-z><C-y><Esc>
" Make common Select All/Copy/Cut/Paste/Undo keybindings useable under vimperator
noremap <C-V> <C-v>
noremap <C-Z> <C-z>
noremap <C-c> <C-v><C-c>
noremap <C-a> <C-v><C-a>
cnoremap <C-c> <C-v><C-c>
cnoremap <C-v> <C-v><C-v>
cnoremap <C-x> <C-v><C-x>
inoremap <C-a> <C-v><C-a>
inoremap <C-c> <C-v><C-c>
inoremap <C-v> <C-v><C-v>
inoremap <C-x> <C-v><C-x>
inoremap <C-z> <C-v><C-z>
inoremap <C-y> <C-v><C-y>
" restore some useful default keybindings offered by origial firefox
noremap <Silent> <C-d> :dialog<Space>addbookmark<CR><Esc>
noremap <Silent> <C-o> :dialog<Space>openfile<CR>
noremap <Silent> <C-p> :dialog<Space>preferences<CR>
noremap <Silent> <C-i> :dialog<Space>pageinfo<CR>
"---------------------------------------------------------------------------------------------
" Vimperator Options
"---------------------------------------------------------------------------------------------
" Show standard toolbar
"set guioptions+=T
" Show Bookmark toolbar
set guioptions+=B
" Number the tab
set guioptions+=n
" better searching experience
set incsearch
set ignorecase
set smartcase
" always show status-line
set laststatus=2
" show mode in the command-line
set showmode
" Try to stay in Normal mode after loading a web page
set focuscontent
" use gVIm as external editor
set editor="gvim -f"
" always sort the auto-completion candidates
set wildoptions="sort"
set wildmode="list:full"
"set complete=l
set nextpattern=\s*下一页|下一张|下页\s*,\b[Nn]ext\b,^>$,^(>>|››|»)$,^(>|»),(>|»)$,\bmore\b
set previouspattern=\s*上一页|上一张|上页\s*,\bprev|Prev|previous\b,^<$,^(<<|‹‹|«)$,^(<|«),(<|«)$
" wait 800ms before automatically following a non-unique numerical hint
set hinttimeout=800
"---------------------------------------------------------------------------------------------
" Firefox preferences
"---------------------------------------------------------------------------------------------
set! browser.tabs.tabMinWidth=100
set! browser.tabs.tabMaxWidth=160
" Always startup firefox with blank page
set! browser.startup.page=0
" Do not use font specified in HTML pages; use system defaults.
set! browser.display.use_document_fonts=0
" Do not use proxy, by decault
set! network.proxy.type=0
"---------------------------------------------------------------------------------------------
" Auto-Commands
"---------------------------------------------------------------------------------------------
" PassThrough gmail and greader
:autocmd LocationChange .* :js modes.passAllKeys = /mail\.google\.com|www\.google\.com\/reader\/view|www\.google\.com\/calendar/.test(buffer.URL)
" Use gVim to edit gmail content
autocmd LocationChange mail\.google\.com :set editor='gvim -f -c \'set ft=mail\' '
"---------------------------------------------------------------------------------------------
" Abbreviations
"---------------------------------------------------------------------------------------------
""---------------------------------------------------------------------------------------------
"" Js scripts
""---------------------------------------------------------------------------------------------
" generic utility for toggle ui elements
js<<EOF
toggle_ui_element = function (name)
{
document.getElementById(name).collapsed ^= 1;
}
EOF
" toggle entry in prefs.js( about:config)
js<<EOF
prefs_entry_toggler = function (entry_name, entry_init_value)
{
var entry_curr_value = entry_init_value;
var inner_function = function ()
{
entry_curr_value ^= 1;
var commands = "set! " + entry_name + "=" + entry_curr_value;
//alert(commands);
liberator.execute( commands);
}
return inner_function;
}
custom_font_toggler = prefs_entry_toggler("browser.display.use_document_fonts", 0 );
proxy_toggler = prefs_entry_toggler("network.proxy.type", 0 );
EOF
" Because vimperator put all keywords into one single argument, we first split it.
js<<EOF
split_and_rejoin_args = function ( args)
{
// split by space
var keywords = args.split(' ');
var query_string = '';
var length = keywords.length;
// Now we rejoin those keywords with '+'
for( var i = 0; i< length - 1 ; ++i)
{
query_string += keywords[i] ;
query_string += '+' ;
}
// Don't forget the last keyword!
query_string += keywords[length-1] ;
// this query string should be encoded, becase it may contain special charatctr(e.g,chinese word)
// query_string = encodeURIComponent(query_string);
return query_string;
}
make_keywords_usable_in_url = function (args)
{
return encodeURIComponent(split_and_rejoin_args(args));
}
EOF
"Show the feed-button, even if the address-bar is not displayed"
js<<EOF
var show_feed_button = function()
{
var feedPanel = document.createElement("statusbarpanel");
feedPanel.setAttribute("id", "feed-panel-clone");
feedPanel.appendChild(document.getElementById("feed-button"));
feedPanel.firstChild.setAttribute("style", "padding: 0; max-height: 16px;");
document.getElementById("status-bar")
.insertBefore(feedPanel, document.getElementById("security-button"));
}
show_feed_button();
EOF
js<<EOF
search_in_verycd = function (args)
{
var query_string = make_keywords_usable_in_url(args);
var prefix = 'http://www.verycd.com/search/folders?field=title&kw=';
var suffix = '&rev=true&q=&from=&c2=0&range=&catalog=&status=all&sort=file_bytes';
var full_url = prefix + query_string + suffix;
liberator.execute('tabopen ' + full_url );
}
EOF
js<<EOF
search_in_shooter = function (args)
{
var query_string = make_keywords_usable_in_url(args);
var prefix = 'http://shooter.cn/search/Sub:' ;
var suffix = '/?x=0&y=0&';
var full_url = prefix + query_string + suffix ;
liberator.execute('tabopen ' + full_url );
}
EOF
js<<EOF
search_in_acfun = function (args)
{
var query_string = make_keywords_usable_in_url(args);
var prefix = 'http://acfun.cn/plus/search.php?kwtype=0&keyword=' ;
var suffix = '&searchtype=titlekeyword' ;
var full_url = prefix + query_string + suffix;
liberator.execute('tabopen ' + full_url );
}
EOF
" Search specified keyword in wikipedia
js<<EOF
search_in_wikipedia = function (keyword)
{
liberator.execute('tabopen wikipedia ' + keyword);
}
EOF
js<<EOF
search_in_douban = function (args)
{
var query_string = make_keywords_usable_in_url(args);
var prefix = 'http://www.douban.com/subject_search?search_text=';
var full_url = prefix + query_string;
liberator.execute('tabopen ' + full_url );
}
EOF
js<<EOF
search_in_mp3 = function (args)
{
var query_string = make_keywords_usable_in_url(args);
var prefix = 'http://mp3.sogou.com/music.so?pf=mp3&as=&st=&ac=1&query=';
var suffix = '&class=1';
var full_url = prefix + query_string;
liberator.execute('tabopen ' + full_url );
}
EOF
js<<EOF
search_in_netyi = function (args)
{
var query_string = make_keywords_usable_in_url(args);
var prefix = 'http://netyi.net/Search.aspx?query=';
var full_url = prefix + query_string;
liberator.execute('tabopen ' + full_url );
}
EOF
js<<EOF
search_in_gigapedia = function (args)
{
var query_string = make_keywords_usable_in_url(args);
var prefix = 'http://gigapedia.info/1/';
var full_url = prefix + query_string;
liberator.execute('tabopen ' + full_url );
}
EOF
js<<EOF
search_in_vim_org = function (args)
{
// vim.org use 'key1+key2' style
var query_string = split_and_rejoin_args(args);
var prefix = 'http://www.vim.org/scripts/script_search_results.php?keywords='
var suffix = '&script_type=&order_by=rating&direction=descending&search=search';
var full_url = prefix + query_string + suffix;
liberator.execute('tabopen ' + full_url );
}
EOF
js<<EOF
search_in_stackoverflow = function (args)
{
// stackoverflow use 'key1+key2' style
var query_string = split_and_rejoin_args(args);
var prefix = 'http://stackoverflow.com/search?q='
var full_url = prefix + query_string ;
liberator.execute('tabopen ' + full_url );
}
EOF
" search in wikipedia Chinese version
js<<EOF
search_in_wikipedia_zh = function (args)
{
var query_string = make_keywords_usable_in_url(args);
var prefix = 'http://zh.wikipedia.org/zh-cn/';
var full_url = prefix + query_string;
liberator.execute('tabopen ' + full_url );
}
EOF
" search in Amazon.com
js<<EOF
search_in_amazon = function (args)
{
var query_string = make_keywords_usable_in_url(args);
var prefix = 'http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Dstripbooks&field-keywords=';
var full_url = prefix + query_string;
liberator.execute('tabopen ' + full_url );
}
EOF
js<<EOF
search_in_firefox_addon = function (args)
{
var query_string = make_keywords_usable_in_url(args);
var prefix = 'https://addons.mozilla.org/zh-CN/firefox/search?q=';
var suffix = '&cat=all';
var full_url = prefix + query_string;
liberator.execute('tabopen ' + full_url );
}
EOF
" Lookup online dictionary of youdao.com
js<<EOF
lookup_youdao_dictionary= function (args)
{
var query_string = make_keywords_usable_in_url(args);
var prefix = 'http://dict.yodao.com/search?q=';
var suffix = '&btnindex=&ue=utf8&keyfrom=dict.index';
var full_url = prefix + query_string + suffix;
liberator.execute('tabopen ' + full_url );
}
EOF
"Lookup specified *nix commands in online manpages
js<<EOF
lookup_manpage = function (keyword)
{
var prefix = 'http://www.google.com/cse?q=';
var suffix = '&sa=Search&ie=ISO-8859-1&cx=partner-pub-5823754184406795%3A54htp1rtx5u&cof=FORID%3A9#927';
var full_url = prefix + keyword + suffix ;
liberator.execute('tabopen ' + full_url );
}
EOF
" Reload vimperatorrc
js <<EOF
load_vimperatorrc= function ()
{
var platform = navigator.platform;
if (platform.indexOf("Linux") != -1 ) // under linux
{
liberator.execute( 'source ~/.vimperatorrc' );
}
else if ( platform.indexOf("Win") != -1 ) // under windows
{
liberator.execute( 'source ~/_vimperatorrc' );
}
}
EOF
" set commandline' bgcolor as dark silver grey
hi CmdLine background: #828282 ; font-family: monospace; padding: 1px;
" Highlight the vimperator command line with grennyello background when you're in it
javascript <<EOF
(function() {
var inputElement = document.getElementById('liberator-commandline-command');
function swapBGColor(event) {
//inputElement.style.backgroundColor = event.type == "focus" ? "yellow" : "";
inputElement.style.backgroundColor = event.type == "focus" ? "GreenYellow ": "";
}
inputElement.addEventListener('focus', swapBGColor, false);
inputElement.addEventListener('blur', swapBGColor, false);
})();
EOF
"the highlight for hints
highlight Hint font-family: monospace; font-size: 13px; font-weight: bold; color: white; background-color: red; border-color: ButtonShadow; border-width: 0px; border-style: solid; padding: 0px 1px 0px 1px
""---------------------------------------------------------------------------------------------
"" Map to js functions
""---------------------------------------------------------------------------------------------
" toggle Firefox menu-bar
noremap <Silent> <F1> :js toggle_ui_element('toolbar-menubar')<CR>
" toggle Firefox nav-bar
noremap <Silent> <F2> :js toggle_ui_element('nav-bar')<CR>
" toggle Firefox bookmark-bar
noremap <Silent> <F3> :js toggle_ui_element('PersonalToolbar')<CR>
" toggle status-bar
noremap <Silent> <F4> :js toggle_ui_element('status-bar')<CR>
" toggle diigo-toolbar
noremap <Silent> <F5> :js toggle_ui_element('diigotb-toolbar')<CR>
" toggle google-toolbar
noremap <Silent> <F6> :js toggle_ui_element('gtbToolbar')<CR>
" search firefox addons
command! -nargs=* Addon :js search_in_firefox_addon("<args>")
noremap A :Addon<Space>
" search Amazon.com
command! -nargs=* Amazon :js search_in_amazon("<args>")
noremap a :Amazon<Space>
" lookup word in yodao dictionary
command! -nargs=* Dict :js lookup_youdao_dictionary("<args>")
noremap c :Dict<Space>
" Search in douban.com
command! -nargs=* Douban :js search_in_douban("<args>")
noremap <Leader>d :Douban<Space>
command! -nargs=* Music :js search_in_mp3("<args>")
noremap m :Music<Space>
" lookup online manpages; Note, we override the default 'm' key utility
command! -nargs=* Man :js lookup_manpage("<args>")
noremap <Leader>m :Man<Space>
" Search in gigapedia.com
command! -nargs=* Gigapedia :js search_in_gigapedia("<args>")
noremap <Leader>g :Gigapedia<Space>
" search vim.org
command! -nargs=* Vim :js search_in_vim_org("<args>")
" search in stackoverflow.com
command! -nargs=* Stack :js search_in_stackoverflow("<args>")
" searhc in shooter.cn for subtitles
command! -nargs=* Shooter :js search_in_shooter("<args>")
noremap S :Shooter<Space>
command! -nargs=* VeryCD :js search_in_verycd("<args>")
noremap v :VeryCD<Space>
command! -nargs=* Ac :js search_in_acfun("<args>")
noremap v :VeryCD<Space>
" search in wikipedia
command! -nargs=* Wiki :js search_in_wikipedia("<args>")
noremap w :Wiki<Space>
" search in wikipedia Chinese version
command! -nargs=* WikiZh :js search_in_wikipedia_zh("<args>")
noremap W :WikiZh<Space>
" reload vimperatorrc
command! Source :js load_vimperatorrc()
noremap <Leader>v :Source<CR>
command! Font :js custom_font_toggler()
noremap <Leader>c :Font<CR>
command! Proxy :js proxy_toggler()
noremap <Leader>p :Proxy<CR>
"" vim: set ft=vimperator: