Skip to content

Instantly share code, notes, and snippets.

View bouzuya's full-sized avatar

bouzuya bouzuya

View GitHub Profile
@bouzuya
bouzuya / gist:1885339
Created February 22, 2012 14:26
autoload/*.vim <-> plugin/*.vim
function! s:open_pair_file()
let path = expand('%:p')
let pairs = [
\ ['/autoload/\([^/]\+\).vim$', '/plugin/\1.vim'],
\ ['/plugin/\([^/]\+\).vim$', '/autoload/\1.vim']
\ ]
for [pat, sub] in pairs
if match(path, pat) != -1
execute 'hide' 'edit' substitute(path, pat, sub, '')
break
" http://subtech.g.hatena.ne.jp/motemen/20080504/1209838652
nnoremap <expr> ^ search('^\s*\%#\S', 'bn') ? '0' : '^'
nnoremap <expr> 0 col('.') == 1 ? '^' : '0'
@bouzuya
bouzuya / sid.vim
Created February 27, 2012 11:15
vim s:snr() & s:sid() & s:parse_script_names() & s:path_to_snr()
function! s:snr()
let sfile = expand('<sfile>')
return matchstr(sfile, '<SNR>\zs\d\+\ze_snr$')
endfunction
function! s:sid()
let snr = s:snr()
return printf('<SNR>%s_', snr)
endfunction
@bouzuya
bouzuya / nnoremap-p.vim
Created February 28, 2012 13:19
nnoremap <expr> p col('.') !=# 1 ? 'p' : 'P'
nnoremap <expr> p col('.') == 1 ? 'P' : 'p'
@bouzuya
bouzuya / gist:3120143
Created July 16, 2012 02:56
Hello, Gist.vim!
Host 560
HostName very.long.host.name
User user560
Port 560
IdentityFile ~/.ssh/id_rsa.560
function! s:yank_gist()
let gist_id = input('gist? ')
execute 'Gist' gist_id
let match = matchlist(bufname('%'), '^gist:\(\d*\)/\(.*\)$')
if empty(match)
echoerr 'no match'
return
endif
let gist_url = printf('https://gist.github.com/%s.js?file=%s', match[1], match[2])
let code = join(getline(1, '$'), "\n")
//samba/shared/repos/git /repos cifs user=user,password=password 0 0
javascript:
(function(){
var id = 'bouzuya-22';
var pattern = /^http:\/\/www\.amazon\.co\.jp(?:.*)\/(?:(?:gp\/product)|(?:dp))\/([0-9A-Za-z]{10}).*$/;
var result = location.href.match(pattern);
if (result == null) {
return;
}
var text = document.createTextNode('A!');
var href = 'http://amazon.jp/o/ASIN/' + result[1] + '/' + id;
javascript:(function(){var f="bouzuya-22";var d=/^http:\/\/www\.amazon\.co\.jp(?:.*)\/(?:(?:gp\/product)|(?:dp))\/([0-9A-Za-z]{10}).*$/;var a=location.href.match(d);if(a==null){return}var e=document.createTextNode("A!");var b="http://amazon.jp/o/ASIN/"+a[1]+"/"+f;var c=document.createElement("a");c.appendChild(e);c.setAttribute("href",b);document.getElementById("btAsinTitle").appendChild(c);return false})();