git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.

From
Pierre Habouzit <madcoder@debian.org>
Date
Oct 17, 2006, 10:38 UTC
Message-ID
<200610171238.04372.madcoder@debian.org>
In-Reply-To
<802d21790610170122j6191ba51l2c39d3bc6a3475b@mail.gmail.com>
Le mar 17 octobre 2006 10:22, Peter Baumann a écrit :
Show 96 quoted lines
> 2006/10/17, Pierre Habouzit <madcoder@debian.org>:
> > Signed-off-by: Pierre Habouzit <madcoder@debian.org>
> > ---
> >  contrib/vim/README                 |    6 ++++
> >  contrib/vim/ftplugin/gitcommit.vim |   61
> > ++++++++++++++++++++++++++++++++++++ 2 files changed, 67
> > insertions(+), 0 deletions(-)
> >
> > diff --git a/contrib/vim/README b/contrib/vim/README
> > index 9e7881f..26c1682 100644
> > --- a/contrib/vim/README
> > +++ b/contrib/vim/README
> > @@ -6,3 +6,9 @@ To syntax highlight git's commit message
> >       $ cat >>$HOME/.vimrc <<'EOF'
> >       autocmd BufNewFile,BufRead COMMIT_EDITMSG set
> > filetype=gitcommit EOF
> > +
> > +To use the fancy split-view with the currently commited diff, you
> > need to: +  1. Copy ftplugin/gitcommit.vim to vim's ftplugin
> > directory: +     $ mkdir -p $HOME/.vim/ftplugin
> > +     $ cp ftplugin/gitcommit.vim $HOME/.vim/ftplugin
> > +  2. Auto-detect the editing of git commit files (see above).
> > diff --git a/contrib/vim/ftplugin/gitcommit.vim
> > b/contrib/vim/ftplugin/gitcommit.vim new file mode 100644
> > index 0000000..f9efd59
> > --- /dev/null
> > +++ b/contrib/vim/ftplugin/gitcommit.vim
> > @@ -0,0 +1,61 @@
> > +if exists("b:did_ftplugin")
> > +  finish
> > +endif
> > +
> > +let b:did_ftplugin = 1
> > +
> > +setlocal tw=74
> > +setlocal nowarn nowb
> > +
> > +"{{{ function Git_diff_windows
> > +
> > +function! Git_diff_windows()
> > +    let i = 0
> > +    let list_of_files = ''
> > +
> > +    " drop everything until '#  (will commit)' and the next empty
> > line +    while i <= line('$')
> > +        let line = getline(i)
> > +        if line =~ '^#\s*(will commit)$'
> > +            let i = i + 2
> > +            break
> > +        endif
> > +
> > +        let i = i + 1
> > +    endwhile
> > +
> > +    " read file names until we have EOF or an empty line
> > +    while i <= line('$')
> > +        let line = getline(i)
> > +        if line =~ '^#\s*[a-z ]*:.*->.*$'
> > +            let file = substitute(line,
> > '\v^#[^:]*:.*->\s*(.*)\s*$', '\1', '') +            let
> > list_of_files = list_of_files . ' '.file
> > +            let file = substitute(line,
> > '\v^#[^:]*:\s*(.*)\s*->.*$', '\1', '') +            let
> > list_of_files = list_of_files . ' '.file
> > +        elseif line =~ '^#\s*[a-z ]*:'
> > +            let file = substitute(line, '\v^#[^:]*:\s*(.*)\s*$',
> > '\1', '') +            let list_of_files = list_of_files . ' '.file
> > +        elseif line =~ '^#\s*$'
> > +            break
> > +        endif
> > +
> > +        let i = i + 1
> > +    endwhile
> > +
> > +    if list_of_files == ""
> > +        return
> > +    endif
> > +
> > +    rightbelow vnew
>
> I find it confusing that you split vertically, especially if I work
> in small terminals.
> I would prefere a horizontal split, thats why I changed it to the way
> to the way it is
> handled in the svn.vim commit case:
>
> below new
>
> > +    silent! setlocal ft=diff previewwindow bufhidden=delete
> > nobackup noswf nobuflisted nowrap buftype=nofile +    exe 'normal
> > :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . "\n1Gdd" +   
> > exe 'normal :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . "
> > \| git apply --stat\no\<esc>1GddO\<esc>"
>
> Why changing directory? I had to remove the cd .. to make it work.
> Otherwise git diff couldn't find the repository.

because for me, wherever I'm from, the cwd is .git/ but it's maybe due to the fact that I use autochdir, I don't know.

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Previous: Peter BaumannNext: Peter Baumann
Message 4 of 23 in “be more vim-ish, and also syntax hilight Signed-off-by lines.”
  1. be more vim-ish, and also syntax hilight Signed-off-by lines.Pierre Habouzit, Oct 17, 2006
  2. nice ftplugin for vim, that shows the commited diff in a split'ed buffer.Pierre Habouzit, Oct 17, 2006
  3. Peter BaumannOct 17, 2006
  4. Pierre HabouzitOct 17, 2006
  5. Peter BaumannOct 17, 2006
  6. Pierre HabouzitOct 17, 2006
  7. Christian MICHONOct 17, 2006
  8. Junio C HamanoOct 17, 2006
  9. Petr BaudisOct 18, 2006
  10. Junio C HamanoOct 17, 2006
  11. contrib/vim patches, replace the previous setPierre Habouzit, Oct 18, 2006
  12. contrib/vim patches, replace the previous setPierre Habouzit, Oct 18, 2006
  13. be more vim-ish, and also syntax hilight Signed-off-by lines.Pierre Habouzit, Oct 18, 2006
  14. Nice ftplugin for vim, that shows the commited diff in a split'ed buffer.Pierre Habouzit, Oct 18, 2006
  15. Pierre HabouzitOct 18, 2006
  16. Make the ftplugin right wrt gitdirPierre Habouzit, Oct 18, 2006
  17. be more robust wrt the git-dir.Pierre Habouzit, Oct 18, 2006
  18. Jeff KingOct 18, 2006
  19. Pierre HabouzitOct 18, 2006
  20. Jeff KingOct 18, 2006
  21. Pierre HabouzitOct 18, 2006
  22. Jeff KingOct 18, 2006
  23. Jeff KingOct 18, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.