Created
September 17, 2015 06:35
-
-
Save jwarby/54769b9dd4dca15ecda8 to your computer and use it in GitHub Desktop.
Append hashtags to the end of a commit message in Vim - intended for adding the initials of peer reviewers, but will work for any tags (you may want to change the function name if so). Usage: :PRed JB EC / :PRed JB / :PRed JB EC DS, etc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! AddPeerReviewerInitials(...) | |
" Go to the top of the file | |
execute ':normal gg' | |
" Find the first comment line, and go up one line | |
let lineIndex = search('^#') - 1 | |
" If line is blank, go up another one (my setup adds a new line when amending commit messages) | |
if !getline(lineIndex) | |
let lineIndex = lineIndex - 1 | |
endif | |
let index = 1 | |
" Loop through tags and append to end of line | |
while index <= a:0 | |
execute lineIndex . ':normal A #' . a:{index} | |
let index = index + 1 | |
endwhile | |
endfunction | |
command! -nargs=+ -complete=command PRed call AddPeerReviewerInitials(<f-args>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment