Custom script for git blame from vim -


i want minimum way of using git blame vim (i dont want use whole fugative plugin). have right this:

this function vim page , enables me open shellcomands in scratch buffer.

function! s:executeinshell(command)   let command = join(map(split(a:command), 'expand(v:val)'))   let winnr = bufwinnr('^' . command . '$')   silent! execute  winnr < 0 ? 'botright new ' . fnameescape(command) : winnr . 'wincmd w'   setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap number   echo 'execute ' . command . '...'   silent! execute 'silent %!'. command   silent! execute 'resize ' . line('$')   silent! redraw   silent! execute 'au bufunload <buffer> execute bufwinnr(' . bufnr('#') . ') . ''wincmd w'''   silent! execute 'nnoremap <silent> <buffer> <localleader>r :call <sid>executeinshell(''' . command . ''')<cr>'   echo 'shell command ' . command . ' executed.' endfunction command! -complete=shellcmd -nargs=+ shell call s:executeinshell(<q-args>) 

together above function do:

noremap <leader>b :shell git blame -l line(".") - 5, line(".") + 5 %<cr> 

to git blame window rows around cursor position in current buffer.

now have 2 questions:

1: how can make scratch buffer opens read can close using q? make change in function :shell comands can closed q.

2: how can line(".") - 5 expand current line - 5 row number?

to make buffer read-only , not modifiable, can put

setlocal readonly nomodifiable 

at end of function.

in case of next question, can use execute , eval

noremap <leader>b :execute "shell git blame -l " . eval(line(".")-5)) . ",+10 %"<cr> 

i recommend read these descriptions, , help in general:


also here link mentioned function on wikia.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -