├── README.md └── plugin └── github.vim /README.md: -------------------------------------------------------------------------------- 1 | github.vim 2 | = 3 | http://github.com/solars/github_vim/ 4 | 5 | I tried to remove the dependency on drnics github-tmbundle scripts in this branch, 6 | please report any errors and feel free to correct/suggest/add. 7 | 8 | ##Description 9 | 10 | 11 | This is a quick and dirty vim plugin to use some github features locally from vim. 12 | 13 | It enables you to: 14 | 15 | - open a link to the corresponding github file of a local vim selection 16 | - add a comment to the corresponding github commit of a locally selected line 17 | - yank a link to the corresponding github file of a local vim selection into the system clipboard 18 | 19 | ##Suggested installation 20 | 21 | The file structure should be clear, just copy the github.vim into ~/.vim/plugin/ 22 | 23 | ##Installing when using [Pathogen](https://github.com/tpope/vim-pathogen) 24 | 25 | cd ~/.vim/bundle 26 | git clone git@github.com:solars/github-vim.git 27 | 28 | ##Usage 29 | 30 | - Comment Commit: on the relevant line Press 'ghc' in normal mode 31 | - Open Selection: create a selection in visual mode and press 'gho' 32 | - Yank Selection: create a selection in visual mode and press 'ghy' 33 | 34 | To remap the keybinding in your ~/.vimrc use: 35 | 36 | - map GithubOpen 37 | - map GithubComment 38 | 39 | ##Notes 40 | 41 | Since this is my first vim plugins, feel free to send corrections or improvements :) 42 | sol@textmode.at 43 | -------------------------------------------------------------------------------- /plugin/github.vim: -------------------------------------------------------------------------------- 1 | " https://github.com/solars/github-vim/ 2 | " sol@textmode.at 3 | 4 | if exists("loaded_github") || &cp 5 | finish 6 | endif 7 | 8 | 9 | " --- main functions --- " 10 | function! s:Hash(n1,n2) 11 | if a:n1 == a:n2 12 | return '#L' . a:n1 13 | else 14 | return '#L' . a:n1 . ',L' . a:n2 15 | endif 16 | endfunction 17 | 18 | function! s:Open() range 19 | if empty(s:RepositoryRoot()) || empty(s:Remote()) 20 | call s:error("File not in repository or no remote found!") 21 | else 22 | let url = s:ReposUrl().'/'.s:RelPath(). s:Hash(a:firstline,a:lastline) 23 | call s:OpenUrl(url) 24 | end 25 | endfunction 26 | 27 | function! s:Yank() 28 | if empty(s:RepositoryRoot()) || empty(s:Remote()) 29 | call s:error("File not in repository or no remote found!") 30 | else 31 | let url = s:ReposUrl().'/'.s:RelPath() . s:Hash(a:firstline,a:lastline) 32 | call s:YankUrl(url) 33 | echo "GitHub URL: " . url 34 | end 35 | endfunction 36 | 37 | function! s:Comment() 38 | if empty(s:RepositoryRoot()) || empty(s:Remote()) 39 | call s:error("File not in repository or no remote found!") 40 | else 41 | let url = s:ReposUrl().'/'.s:RelPath() . s:Hash(a:firstline,a:lastline) 42 | let line = line('.') 43 | let output = s:CdExec(s:RepositoryRoot(),'git blame -l -s -L '.line.','.line.' '.s:RelPath()) 44 | if empty(output) 45 | s:error("No commit found") 46 | return 47 | end 48 | let commit = split(output)[0] 49 | let index=s:CommitIndex(commit) 50 | let url = s:ProjectUrl().'/commit/'.commit.'/'.s:RelPath().'#diff-'.index 51 | call s:OpenUrl(url) 52 | endif 53 | endfunction 54 | 55 | 56 | " --- key mappings --- " 57 | 58 | if !hasmapto('GithubComment', 'n') 59 | nmap ghc GithubComment 60 | endif 61 | nnoremap