Vim: Open current line on Atlassian Stash (Bitbucket Server)

This is based on Felix Geisendörfer Vim Trick: Open current line on GitHub.

Step 1. Create a git alias

# ~/.gitconfig
[alias]
  url =! bash -c 'git config --get remote.origin.url | sed -E "s/.+\\.ru\\\\/\\(.+\\)\\\\/\\(.+\\)\\.git$/https:\\\\/\\\\/stash\\\\.yourcompanyname\\\\.com\\\\/projects\\\\/\\\\1\\\\/repos\\\\/\\\\2\\\\/browse/g"'

Change domain name from ‘stash.yourcompanyname.com’ to something real. Pay attention to ‘.’ escaping.

Step 2. Create a mapping in Vim

; ~/.vimrc
nnoremap <leader>ou :!echo `git url`/%?at=`git rev-parse HEAD`\#<C-R>=line('.')<CR> \| xargs open<CR><CR>

Step 3. Enjoy

My dotfiles: https://github.com/melekes/dotfiles

Anton Kaliaev

Software engineer, blogger, public speaker, traveler

Ulyanovsk, Russia http://homeonrails.com