Code Monkey home page Code Monkey logo

vim-gh-line's Introduction

vim-gh-line

Build Status

A Vim plugin that opens a link to the current line on GitHub (and also supports Bitbucket, self-deployed GitHub, Googlesource, GitLab, and SourceHut).

gh-line

How to install

Vundle

Put this in your .vimrc

Bundle 'ruanyl/vim-gh-line'

Then restart vim and run :BundleInstall. To update the plugin to the latest version, you can run :BundleUpdate.

How to use

Default key mapping for a blob view: <leader>gh

Default key mapping for a blame view: <leader>gb

Default key mapping for repo view: <leader>go

To disable default key mappings:

let g:gh_line_map_default = 0
let g:gh_line_blame_map_default = 1

Use your own mappings:

let g:gh_line_map = '<leader>gh'
let g:gh_line_blame_map = '<leader>gb'

Use a custom program to open link:

let g:gh_open_command = 'open '

Copy link to a clipboard instead of opening a browser:

let g:gh_open_command = 'fn() { echo "$@" | pbcopy; }; fn '

Use canonical version hash for url in place of branch name:

let g:gh_use_canonical = 1

Working with multiple remotes

When work with repo which has multiple remotes, the plugin will ask for your input of which remote you want to use. The plugin always remember the last remote selection and use it as default remote name the next time you use it.

But you can use the following command to enforce to show the interactive input and change the default remote that's set previously:

:GHInteractive
:GBInteractive

it is also possible to always enforce interactive input by setting:

" gh_always_interactive is 0 by default
g:gh_always_interactive = 1

Different git hosting alternatives

Use self-deployed GitHub:

let g:gh_github_domain = "<your github domain>"

Use self-deployed GitLab:

Use a self deployed gitlab (the value is a matching regex, i.e. you can use multiple domains separated with |):

let g:gh_gitlab_domain = "<your gitlab domain>"
Use self deployed gitlab only with http:
let g:gh_gitlab_only_http = 1

Use self-deployed SourceHut:

Use a self deployed SourceHut (the value is a matching regex, i.e. you can use multiple domains separated with |):

let g:gh_srht_domain = "<your sourcehut domain>"

Use a git remote with Cgit front end:

For Cgit frontends, the user needs to specify a pattern -> sub mapping to compile the url. vim-gh-line uses the origin remote of your repo heuristicly to come up with the url of the hosting site. For cgit deployments, there is no simple heuristic to compile the url of the cgit frontend's webpage.

let g:gh_cgit_url_pattern_sub = [ [{pattern}, {sub}], ... ]

The g:gh_cgit_url_pattern_sub variable is a list of tuples. Each tuple is of form [{pattern}, {sub}]. The origin remote in a repo is matched against each pattern in the tuples in g:gh_cgit_url_pattern_sub in order. The sub of the first tuple whose pattern matches will be used in a substitute() command to compile the final url.

For example say you are working on the bash source code. The origin of your local repo is https://git.savannah.gnu.org/git/bash.git. And the Cgit front end url for a line link looks like http://git.savannah.gnu.org/cgit/bash.git/tree/Makefile.in?id=64447609994bfddeef1061948022c074093e9a9f#n12.

The g:gh_cgit_url_pattern_sub could be

let g:gh_cgit_url_pattern_sub = [
    \ ['.\+git.savannah.gnu.org/git/', 'http://git.savannah.gnu.org/cgit/'],
 \ ]

In addition to bash, say you also do kernel development in https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git say the remote you use is git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

To handle both bash and kernel repos, the following g:gh_cgit_url_pattern_sub would work.

let g:gh_cgit_url_pattern_sub = [
    \ ['.\+git.savannah.gnu.org/git/', 'http://git.savannah.gnu.org/cgit/'],
    \ ['.\+git.kernel.org/', 'https://git.kernel.org/'],
 \ ]

Debugging

For getting verbose prints from vim-gh-line plugin set.

let g:gh_trace = 1

vim-gh-line's People

Contributors

ruanyl avatar ahakanbaba avatar gko avatar kostyaesmukov avatar bgaluszka avatar nickatsegment avatar brandur avatar bitfehler avatar erikr avatar haomingw avatar volvofixthis avatar mattiaslundberg avatar acerom avatar waplet avatar geeksam avatar smkent avatar terryding77 avatar yiminglu avatar kevinhwang91 avatar notomo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.