Skip to content

Instantly share code, notes, and snippets.

@troyp
Last active September 30, 2018 09:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save troyp/cf1a640576713c46ee8b to your computer and use it in GitHub Desktop.
Save troyp/cf1a640576713c46ee8b to your computer and use it in GitHub Desktop.
.cvimrc
" ________
" | |
" | CVIMRC |
" |________|
" ,----------,
" | settings |
" '----------'
set localconfig
let configpath = '~/.cvimrc/.cvimrc'
let homedirectory = '/home/troy'
let mapleader = ','
set smoothscroll
let scrollduration = 100
set showtabindices
set sortlinkhints
set dimhintcharacters
set cncpcompletion
let barposition = 'bottom'
let nextmatchpattern = '((?!first)(next|older|more|>|›|»|▸|forward|次|下|后| )+)'
let previousmatchpattern = '((?!last)(prev(ious)?|newer|less|<|‹|«|◂|back|前|上| )+)'
" ,---------------,
" | searchengines |
" '---------------'
" let searchlimit = 25
" let completionengines = ['google', 'wikipedia', 'imdb', 'amazon', 'wolframalpha', 'duckduckgo']
let searchengine gh = "https://github.com/search?utf8=%E2%9C%93&q=%s&type=Repositories&ref=searchresults"
let searchengine jisho = "http://jisho.org/search/%s"
let searchengine trja = "https://translate.google.com/#ja/en/%s"
" ,----------,
" | mappings |
" '----------'
unmap x
iunmap <C-v>
imap <C-o> editWithVim
imap <C-a> beginningOfLine
imap <C-i> selectAll
imap <C-k> deleteToEnd
map <C-v> passKeys
map <C-x><C-c> quitChrome
" map af createActiveTabbedHint
map J scrollPageDown
map K scrollPageUp
map <C-d> scrollFullPageDown
map <C-u> scrollFullPageUp
map <C-h> scrollLeft
map <C-l> scrollRight
map g0 scrollToLeft
map g$ scrollToRight
map gS :viewsource&<CR>
" map gq :restore<Space>
" map a<Space> z<Enter>
" map cn :execute nzz<CR>
" map cN :execute Nzz<CR>
" map <C-d> :file ~/
" map <C-s> openLastHint
" map <C-g> :set smoothscroll!<CR>
" map <C-h> :nohl<CR>
" map cc :set hud!<CR>
" map aa :tabopen g<Space>
" map , :set numerichints!<CR>
" map ga :settings<CR>
map sh :history<Space>
map sj :tabhistory<Space>
map sk<Space> :bookmarks<Space>
map skk :bookmarks /Bookmarks bar/
map b :buffer<Space>
map p openPasteTab
map P openPaste
" ,------,
" | tabs |
" '------'
map h previousTab
map l nextTab
map d closeTab
map u lastClosedTab
map U :restore<Space>
map C :duplicate<CR>
map gt goToTab
map g$ lastTab
map g0 firstTab
map > lastTab
map < firstTab
map <C-h> moveTabLeft
map <C-l> moveTabRight
map <A-;> lastUsedTab
map <C-k> :execute gx$x<CR>
" PREFIX b "
unmap b
map bb :buffer<Space>
map B :buffer<Space>
map bM muteTab
map bp pinTab
map br reloadAllTabs
map bR reloadAllButCurrent
map b> closeTabsToRight
map b< closeTabsToLeft
" ,--------,
" | frames |
" '--------'
"cycle/root frame (frees gf gF)
map ,ff nextFrame
map ,fF rootFrame
map ,fy yankRootUrl
" ,-------,
" | hints |
" '-------'
map gf createMultiHint
map g; ;
" hover (frees q Q)
map ;q createHoverHint
map ;Q createUnhoverHint
map ;e createEditHint
map ;i fullImageHint
map ;r reverseImage
map ;y yankUrl
map gr multiReverseImage
map gy multiYankUrl
" ,---------,
" | browser |
" '---------'
map vr :source ~/.cvimrc/.cvimrc<CR>
" ,------,
" | goto |
" '------'
map ea :chrome extensions<CR>
map e;a :tabopen file:///opt/chrome-extensions<CR>
map eg :rcgist<CR>
map ec :tabopen chrome://flags<CR>
map eh :tabopen chrome://history<CR>
map eo :tabopen file:///opt<CR>
map er :tabopen https://github.com/1995eaton/chromium-vim<CR>
map es :tabopen https://peter.sh/experiments/chromium-command-line-switches/<CR>
map e` :tabopen file:///home/troy<CR>
map e/ :tabopen file:///<CR>
map ee;a :open file:///opt/chrome-extensions<CR>
map eec :open chrome://flags<CR>
map eeh :open chrome://history<CR>
map eee :open chrome://extensions<CR>
map eeo :open file:///opt<CR>
map eer :open https://github.com/1995eaton/chromium-vim<CR>
map ees :open https://peter.sh/experiments/chromium-command-line-switches/<CR>
map ee` :open file:///home/troy<CR>
map ee/ :open file:///<CR>
map ew;a :winopen file:///opt/chrome-extensions<CR>
map ewc :winopen chrome://flags<CR>
map ewh :winopen chrome://history<CR>
map ewe :winopen chrome://extensions<CR>
map ewo :winopen file:///opt<CR>
map ewr :winopen https://github.com/1995eaton/chromium-vim<CR>
map ews :winopen https://peter.sh/experiments/chromium-command-line-switches/<CR>
map ew` :winopen file:///home/troy<CR>
map ew/ :winopen file:///<CR>
" ,------,
" | yank |
" '------'
yankLinkText(link) -> {{
clipboard.copy(link.text);
status.setmessage(link.text,3);
}}
yankPageTitle -> {{
Clipboard.copy(document.title);
status.setmessage(document.title,3);
}}
yankText(link) -> {{
Clipboard.copy(link.text);
Status.setMessage(link.text,3);
}}
copyCurrentTabTitle -> {{
Clipboard.copy(document.title);
Status.setMessage(document.title,3);
}}
unmap yh
map y;d createScriptHint(yankLinkText)
map yh :call yankPageTitle<CR>
map yH yankHighlight
map zy createScriptHint(yankText)
map yt :call copyCurrentTabTitle<CR>
" ,---------,
" | toggles |
" '---------'
map <Leader>te :call editContent<CR>
editContent -> {{
var elts = document.getElementsByTagName("*");
for (i=0; i<elts.length; ++i)
if (elts[i].hasAttribute("contentEditable") && elts[i].contentEditable === "true")
elts[i].contentEditable = "inherit";
else
elts[i].contentEditable = "true";
}}
" ,----------------------, ,-----------,
" | Web Sites & Web Apps | | <Leader>a |
" '----------------------' '-----------'
" Banking "
map <Leader>ab :tabopen @@mybankurl<CR>
" Repos: <Leader>ag "
map <Leader>agh :tabopen https://github.com/troyp<CR>
map <Leader>agb :tabopen https://bitbucket.org/<CR>
" Email: <Leader>am "
map <Leader>amm :tabopen https://mail.google.com/mail/h/1f0xqcpo2pdl3/?f=1<CR>
map <Leader>amg :tabopen https://mail.google.com/mail/u/0/#inbox<CR>
map <Leader>amy :tabopen https://mg.mail.yahoo.com/<CR>
" Paypal "
map <Leader>ap :tabopen https://www.paypal.com/myaccount/home<CR>
" Time "
map <Leader>at :tabopen https://time.is/Sydney<CR>
" Video: <Leader>av "
map <Leader>avn :tabopen https://www.netflix.com/browse/my-list<CR>
" Weather "
map <Leader>aw :tabopen http://www.bom.gov.au/nsw/forecasts/lismore.shtml<CR>
" ,----------------------,
" | same tab: <Leader>a; |
" '----------------------'
" Repos: <Leader>a;g "
map <Leader>a;gh :open https://github.com/troyp<CR>
map <Leader>a;gb :open https://bitbucket.org/<CR>
" Email: <Leader>a;m "
map <Leader>a;mm :open https://mail.google.com/mail/h/1f0xqcpo2pdl3/?f=1<CR>
map <Leader>a;mg :open https://mail.google.com/mail/u/0/#inbox<CR>
map <Leader>a;my :open https://mg.mail.yahoo.com/<CR>
" Paypal "
map <Leader>a;p :open https://www.paypal.com/myaccount/home<CR>
" Time "
map <Leader>a;t :open https://time.is/Sydney<CR>
" Video: <Leader>a;v "
map <Leader>a;vn :open https://www.netflix.com/browse/my-list<CR>
" Weather "
map <Leader>a;w :open http://www.bom.gov.au/nsw/forecasts/lismore.shtml<CR>
" ===============================================================================
" _______
" | |
" | sites |
" |_______|
" ,--------,
" | github |
" '--------'
let @@ghusername = 'troyp'
site 'https://github.com/*' {
map cyy :call ghCopyRepoLinkGit<CR>
map cyh :call ghCopyRepoLinkHttps<CR>
}
ghCopyRepoLinkGit() -> {{
var regex = /[^:]+:\/\/(gist.)?github.com\/([^/]+)\/?([^/#?]+)?(\/.*)?/;
var match = document.URL.match(regex);
var user = match && match[2];
var repo = match && match[3];
var gitlink = user && repo && `git@github.com:${user}/${repo}.git`;
Clipboard.copy(gitlink);
}}
ghCopyRepoLinkHttps() -> {{
var regex = /[^:]+:\/\/(gist.)?github.com\/([^/]+)\/?([^/#?]+)?(\/.*)?/;
var match = document.URL.match(regex);
var user = match && match[2];
var repo = match && match[3];
var httpslink = user && repo && `https://github.com/${user}/${repo}.git`;
Clipboard.copy(httpslink);
}}
" ,---------,
" | netflix |
" '---------'
site 'https://www.netflix.com/*' {
map col :open https://www.netflix.com/browse/my-list<CR>
map coh :open https://www.netflix.com/browse<CR>
map cs :call netflixSearch<CR>
map ctl :tabnew https://www.netflix.com/browse/my-list<CR>
map cth :tabnew https://www.netflix.com/browse<CR>
}
" Downloads require the Netflix Subtitle Downloader userscript "
site 'https://www.netflix.com/watch/*' {
map cc :call netflixToggleSubs<CR>
map cd :script document.querySelector('.track.download').click();<CR>
map cD :script document.querySelector('.track.download-all').click();<CR>
map ]] :call netflixNextEpisode<CR>
map [[ :call netflixPreviousEpisode<CR>
}
site 'https://www.netflix.com/browse' {
map cc :call netflixBrowseCleanup<CR>
}
" let blacklists = ["http://localhost/*","http://lo-th.github.io/*"]
netflixNextEpisode() -> {{
var nextep = document.querySelector('.postplay-button') ||
document.querySelector('.player-postplay-still-hover-container') ||
document.querySelector('.player-next-episode').children[0];
nextep.click();
}}
netflixToggleSubs() -> {{
var subOpts = Array.from(document.querySelector('.player-timed-text-tracks').children);
if (subOpts[1].classList.contains("player-track-selected")) {
subOpts.find(e=>e.innerText.match(/english/i)).click();
} else {
subOpts[1].click();
}
var optDisplay = document.getElementById('player-menu-track-settings');
optDisplay.classList.remove('player-visible');
optDisplay.classList.remove('player-active');
}}
netflixBrowseCleanup() -> {{
var imgLayer = document.querySelector('.static-image.image-layer');
imgLayer.remove();
var billboard = document.querySelector('.billboard-row');
billboard.remove();
}}
netflixSearch() -> {{
var searchIcon = document.querySelector('.icon-search');
searchIcon.click();
}}
netflixPreviousEpisode() -> {{
var title = document.getElementsByClassName('player-status')[0].innerText;
var match = title.match(/season *(\d+).*ep(?:isode)?\.? *(\d+)/i);
var season = parseInt(match[1]);
var ep = parseInt(match[2]);
if (ep == 1) {
document.getElementsByClassName('back-to-seasons')[0].click();
var seasonlist = document.querySelectorAll('.season-list li');
var newSeason = Math.max(1, season - 1);
seasonlist[newSeason - 1].click();
var epList = document.getElementsByClassName('episode-list-item');
var newEpId = epList[epList.length - 1].getAttribute('data-episode-id');
window.open(`https://www.netflix.com/watch/${newEpId}`, '_self');
} else {
var newEp = ep - 1;
var epList = document.getElementsByClassName('episode-list-item');
var newEpId = epList[newEp - 1].getAttribute('data-episode-id');
window.open(`https://www.netflix.com/watch/${newEpId}`, '_self');
}
}}
[{"key":"ctrl+u","action":"scrollupmore","blacklist":false,"sites":"*","open":false,"exported":true,"sitesArray":["*"]},{"key":"ctrl+d","action":"scrolldownmore","blacklist":false,"sites":"*","open":false,"exported":true,"sitesArray":["*"]}]
#!/usr/bin/python3
'''
USAGE: ./cvim_server.py
If you want to use native Vim to edit text boxes
you must be running this script. To begin editing,
first map the editWithVim (e.g. "imap <C-o> editWithVim") mapping.
By default, this script will spawn a gvim ("gvim -f"), but this action
can be changed by setting the VIM_COMMAND variable below
'''
import os
import sys
import shlex
from json import loads
import subprocess
from tempfile import mkstemp
from http.server import HTTPServer, BaseHTTPRequestHandler
PORT = 8001
VIM_COMMAND = 'gvim -f'
def edit_file(content):
fd, fn = mkstemp(suffix='.txt', prefix='cvim-', text=True)
os.write(fd, content.encode('utf8'))
os.close(fd)
subprocess.Popen(shlex.split(VIM_COMMAND) + [fn]).wait()
text = None
with open(fn, 'r') as f:
text = f.read()
os.unlink(fn)
return text
class CvimServer(BaseHTTPRequestHandler):
def do_POST(self):
length = int(self.headers['Content-Length'])
content_str = self.rfile.read(length).decode('utf8')
content = loads(content_str)
self.send_response(200)
self.send_header('Content-Type', 'text/plain')
self.end_headers()
# Block XMLHttpRequests originating from non-Chrome extensions
if not self.headers.get('Origin', '').startswith('chrome-extension'):
edit = ''
else:
edit = edit_file(content['data'])
self.wfile.write(edit.encode('utf8'))
def init_server(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler):
server_address = ('127.0.0.1', PORT)
httpd = server_class(server_address, CvimServer)
httpd.serve_forever()
try:
init_server()
except KeyboardInterrupt:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment