2017/01/30

Vim Git trick

http://felixge.de/2013/08/08/vim-trick-open-current-line-on-github.html

~/.gitconfig:
[alias]
    url =! bash -c 'git config --get remote.origin.url | sed -E "s/.+:\\(.+\\)\\.git$/https:\\\\/\\\\/github\\\\.com\\\\/\\\\1/g"'

~/.vimrc:
nnoremap <leader>o :!echo `git url`/blob/`git rev-parse --abbrev-ref HEAD`/%\#L<C-R>=line('.')<CR> \| xargs open<CR><CR>

--

nnoremap <leader>o :!echo `sed -e 's,:,/,;s,git@,https://,;s,.git$,,' <(git ls-remote --get-url)`/blob/`cat .git/ORIG_HEAD`/%\#L<C-R>=line('.')<CR> \| xargs open<CR><CR>

No comments:

Post a Comment