vim:keys: Fix commit reference when at EOL
Fix the commit reference mapping `<leader>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.
This commit is contained in:
@@ -113,7 +113,9 @@ nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
|
|||||||
" Git bindings
|
" Git bindings
|
||||||
" Insert a commit's subject behind the SHA1 that the cursor is currently on.
|
" Insert a commit's subject behind the SHA1 that the cursor is currently on.
|
||||||
" Mnemonic: "git reference commit"
|
" Mnemonic: "git reference commit"
|
||||||
nmap <leader>grc yiwea<CR><Esc>k:r!git show -s --format='("\%s")' <C-R>0<CR>kJJ
|
" NOTE: This uses `system` and not `:r!` to insert the text directly at the
|
||||||
|
" cursor. `subject[:-2]` cuts off the trailing newline.
|
||||||
|
nmap <leader>grc :let subject=system('git show -s --format="(\"%s\")" <C-R><C-W>')<CR>ea <C-R>=subject[:-2]<CR><Esc>
|
||||||
if exists('g:loaded_fugitive')
|
if exists('g:loaded_fugitive')
|
||||||
nmap <leader>gc :G commit<CR>
|
nmap <leader>gc :G commit<CR>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user