From 733481900f94dea61c48cfbdc0ca09313ede975c Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Fri, 13 May 2022 18:19:28 +0200 Subject: [PATCH] vim:keys: Fix commit reference when at EOL Fix the commit reference mapping `grc` in the case that nothing follows the commit hash on the line. In that case the join would add a trailing space. `gJ` is not suitable as that would break in the other case that text follows. When splitting the line behind the commit hash, the space in front of whatever follows is deleted. Thus when joining everything together at the end, there would be no space between the closing parentheses and the rest. Using the `system()` was the only solution I found to insert the subject directly behind the hash without destroying the formatting and the text behind it. For this to work the trailing newline had to be cut off of git's output. --- .config/vim/vimrc.d/40-keys.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.config/vim/vimrc.d/40-keys.vim b/.config/vim/vimrc.d/40-keys.vim index e918cd7..a6e71ff 100644 --- a/.config/vim/vimrc.d/40-keys.vim +++ b/.config/vim/vimrc.d/40-keys.vim @@ -113,7 +113,9 @@ nnoremap gp '`[' . strpart(getregtype(), 0, 1) . '`]' " Git bindings " Insert a commit's subject behind the SHA1 that the cursor is currently on. " Mnemonic: "git reference commit" -nmap grc yiweak:r!git show -s --format='("\%s")' 0kJJ +" NOTE: This uses `system` and not `:r!` to insert the text directly at the +" cursor. `subject[:-2]` cuts off the trailing newline. +nmap grc :let subject=system('git show -s --format="(\"%s\")" ')ea =subject[:-2] if exists('g:loaded_fugitive') nmap gc :G commit