Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Vim で Git を使う

Posted at

Vim で Git を使う

lambdalisue/gina.vim を使っています。

まだまだ試行錯誤中。

さくっと

  • ログ表示: <Leader>gl
  • バッファでログ表示: <Leader>gL
  • diff表示: <Leader>gd
  • ステータス表示: <Leader>gs
  • ブランチ表示: <Leader>gbb
  • push (ブランチ名に応じて master を変更): <Leader>gp
  • 開いているファイル、選択行を Github で開く: <Leader>oG
  • 差分から検索: <Leader>gg
vimrc
nnoremap <silent> <Leader>gl :!git gl -100<CR>
nnoremap <silent> <Leader>gL :Gina log --graph -100<CR>
nnoremap <silent> <Leader>gd :!git diff<CR>
nnoremap <silent> <Leader>gs :!git status<CR>
nnoremap <Leader>gbb :call popup_atcursor(systemlist('git branch'), #{ moved: "any", border: [], minwidth: &columns/3, minheight: &lines/4 })<CR>
nnoremap <Leader>gp :!git push origin master
nnoremap <Leader>oG :Gina browse :<CR>
xnoremap <Leader>oG :Gina browse :<CR>
nnoremap <Leader>gg :Gina log -p -G""<Left>

変更内容を全コミット

  • 単純なコメント: <Leader>gn
  • 詳細なコメント:
    1. <Leader>gu
    2. <Leader>gc
vimrc
nnoremap <Leader>gn :!git commit -a -m ""<Left>
nnoremap <silent> <Leader>gu :silent !git add -u<CR>
nnoremap <silent> <Leader>gc :!git commit -v<CR>

変更内容の一部をコミット

  • 比較的単純な場合
    1. <Leader>ga
    2. <Leader>gc
vimrc
nnoremap <silent> <Leader>ga :call popup_create(term_start(['git', 'add', '-p'], #{ hidden: 1, term_finish: 'close'}), #{ border: [], minwidth: &columns*9/10, minheight: &lines/2 })<CR>
nnoremap <silent> <Leader>gc :!git commit -v<CR>
  • 比較的複雑な場合
    1. <Leader>gS
    2. 対象のファイルで pp
    3. 当該コミットに取り込む対象を dor で反映、 dol で除外
    4. :w
    5. qt
    6. cc
    7. コミットメッセージを書いて :wq
      1. からの繰り返し
    8. :bdeletle で終わり。
vimrc
nnoremap <silent> <Leader>gS :Gina status -s<CR>
call gina#custom#mapping#nmap('status', 'cc', ':<C-u>Gina commit -v --group=status<CR>', {'noremap': 1, 'silent': 1, 'buffer': 1, 'nowait': 1})
nnoremap qt :tabclose<CR>

直前のコミットを master ブランチにする

  1. ブランチ名変更: <Leader>gbr
  2. 直前のコミットのブランチ名を master へ: <Leader>g-
vimrc
nnoremap <Leader>gbr :!git branch -m<Space>
nnoremap <Leader>g- :!git switch -c master HEAD~<Left><Left><Left><Left><Left><Left>

履歴を辿って変更内容を確認

  1. リポジトリのファイルを開いて <Leader>bl
  2. <CR>, <BS> でコミットを辿って e, s でコミットメッセージを表示
  3. qt で終わり。
vimrc
nnoremap <silent> <Leader>gbl :Gina blame<CR>
call gina#custom#mapping#nmap('blame', 's', ':<C-u>Gina show<CR>', {'noremap': 1, 'silent': 1, 'buffer': 1, 'nowait': 1})
call gina#custom#mapping#nmap('blame', 'e', '<Plug>(gina-blame-echo)', {'noremap': 0, 'buffer': 1, 'nowait': 1})
nnoremap qt :tabclose<CR>
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?