Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fugitive

 Fugitive

This plugin by Tim Pope integrates Git into Vim and brings the editor one step closer to an IDE, as you can take the power to manage, view, and update your repository without ever once leaving the editor to go back to your shell. This talk will walk through some of the many ways you can use Fugitive to improve your workflow.

(Note: you may want to check out my slides from the recent DCBPW if you're not that familiar with git yet, as a primer for this talk)

This talk was initially prepared and presented at the May 9, 2016 Baltimore Vim meetup.

3ed7378b8a83d2952488d4edcd22c406?s=128

Stephen Belcher

May 09, 2016
Tweet

Transcript

  1. About a Month Ago...

  2. DCBPW 2016

  3. Intro to Git

  4. Version Control System

  5. Tracks Changes to Code

  6. Distributed

  7. History is All Local

  8. CLI Based

  9. IDEs

  10. Komodo IDE

  11. Visual Studio

  12. But What About Vim?

  13. tpope/vim-fugitive

  14. "a Git wrapper so awesome, it should be illegal"

  15. I'm still new to life on the run

  16. Fugitive is Command- Mode Based :Git, :Gedit, :Gblame, :Gstatus, etc.

  17. :Gstatus :Gstatus<CR>

  18. :Gstatus

  19. :Gstatus <Ctrl-N>

  20. :Gstatus

  21. :Gstatus <Ctrl-N>

  22. :Gstatus

  23. :Gstatus <CR>

  24. :Gstatus

  25. :Gstatus <Ctrl-W><Up>

  26. :Gstatus

  27. :Gstatus <Ctrl-P>

  28. :Gstatus

  29. :Gstatus D

  30. :Gstatus

  31. :Gstatus ]c

  32. :Gstatus

  33. :Gstatus dp

  34. :Gstatus

  35. :Gstatus <Ctrl-W><Right>

  36. :Gstatus

  37. :Gstatus :w<CR>

  38. :Gstatus

  39. :Gstatus <Ctrl-W><Up>

  40. :Gstatus

  41. :Gstatus r

  42. :Gstatus

  43. :Gstatus

  44. :Gstatus

  45. :Gstatus <Ctrl-W><Up>

  46. :Gstatus

  47. :Gstatus U

  48. :Gstatus

  49. :Gstatus l

  50. :Gstatus

  51. :Gstatus

  52. :Gstatus

  53. :Gstatus :Git cat-file blob 1cf8cc2 > index.html

  54. :Gstatus

  55. :Gstatus <CR>

  56. :Gstatus

  57. :Gstatus l

  58. :Gstatus

  59. :Gstatus <CR>

  60. :Gstatus

  61. :Gstatus

  62. :Gstatus

  63. :Gstatus D

  64. :Gstatus

  65. :Gstatus ]c

  66. :Gstatus

  67. :Gstatus do

  68. :Gstatus

  69. :Gstatus

  70. :Gstatus

  71. :Gstatus do

  72. :Gstatus

  73. :Gstatus :w

  74. :Gstatus

  75. :Gstatus <CR>

  76. :Gstatus

  77. :Gstatus <Ctrl-W><Up>

  78. :Gstatus

  79. :Gcommit cc

  80. :Gcommit

  81. :Gstatus => Staging area power tool

  82. :Gstatus window mappings • <Ctrl-N>/<Ctrl-P> - next/previous file • <CR>

    - edit file under cursor (or cursor line) • D - Diff file (against index or prev commit) • U - Run ":Git checkout" or similar • cc - Run ":Git commit" • - (i.e., a dash/minus) - stage/unstage file under cursor • ...and many others (:help fugitive)
  83. :Gcommit :wq

  84. :Gcommit

  85. :Gcommit <CR>

  86. :Gcommit

  87. <CR>

  88. None
  89. :q

  90. None
  91. <CR>

  92. None
  93. :Gcommit => quick interface to git commit

  94. Benefits of :Gcommit • Access to auto-complete if turned on

    • Can use fugitive :Gdiff and friends to easily inspect individual changes • Can, if absolutely necessary, update the staging area while commit window is open
  95. :Gedit :Gedit 1cf8cc2

  96. :Gedit

  97. :Gedit <CR>

  98. :Gedit

  99. :Gedit :Gedit 568655f

  100. :Gedit

  101. :Gedit <CR>

  102. :Gedit

  103. :Gedit j

  104. :Gedit

  105. :Gedit <CR>

  106. :Gedit

  107. :Gedit 10G

  108. :Gedit

  109. :Gedit zo

  110. :Gedit

  111. :Gedit <CR>

  112. :Gedit

  113. :Gedit :only | Gedit 568655f~

  114. :Gedit

  115. :Gedit <CR>

  116. :Gedit

  117. :Gedit <CR>

  118. :Gedit

  119. :Gedit 12G

  120. :Gedit

  121. :Gedit <CR>

  122. :Gedit

  123. :Gedit /Feb<CR>

  124. :Gedit

  125. :Gedit :Gedit master

  126. :Gedit

  127. :Gedit <CR>

  128. :Gedit

  129. :Gedit <CR>

  130. :Gedit

  131. :Gedit :Gedit gh-pages@{one.year.ago}:index.html

  132. :Gedit

  133. :Gedit <CR>

  134. :Gedit

  135. :Gedit <Ctrl-F>

  136. :Gedit

  137. :Gedit <Ctrl-F>

  138. :Gedit

  139. :Gedit <Ctrl-F>

  140. :Gedit

  141. :Gedit => navigate the history

  142. :Gedit Revisions • All standard Git revisions work (see the

    gitrevisions(7) man page) • Some shortcuts exist just for Fugitive: • - the current file as most-recently committed • ^ the current file as committed one commit ago • ~3 the current file as committed three commits ago • :0 the current file in the staging area
  143. :Gedit and...friends • :Gsplit - open a revision in a

    new split • :Gvsplit - open a revision in a new vertical split • :Gtabedit - open a revision in a new tab • :Gpedit - open a revision in the preview window • :Gbrowse - open a browser to the revision
  144. :Gbrowse • Fairly intelligent (supports line ranges, commit hashes, etc.)

    • Currently supports GitHub remotes • This is deprecated; use tpope's "vim-rhubarb" plugin • Will fall back to using a URL formed off "git-web" standard behavior • Other plugins needed for other custom hosts
  145. :Gblame :Gblame

  146. :Gblame

  147. :Gblame

  148. :Gblame

  149. :Gblame

  150. :Gblame

  151. :Gblame

  152. :Gblame

  153. :Gblame

  154. :Gblame

  155. :Gblame

  156. More Straightforward Commands

  157. :Gpush - Wraps "git push"

  158. :Gpull - Wraps "git pull"

  159. :Gfetch - Wraps "git fetch"

  160. :Gmove - Wraps "git mv" (and updates Vim buffers)

  161. :Gremove - Wraps "git rm" (and updates Vim buffers)

  162. :Gwrite - Writes a file to disk, and also stages

    it
  163. :Gread - Reads a revision over top of the current

    file (but does not write it)
  164. :Gwq - Writes a file to disk, and also stages

    it, and then closes the window
  165. :Gwq - Writes a file to disk, and also stages

    it, and then closes the window
  166. Things I've Yet to Play With

  167. :Gmerge - Handle git merges (handy if you have conflicts

    that need resolving)
  168. :Glog, :Gllog - Walk through git logs (handy for finding

    bugs)
  169. Vimcasts • http://vimcasts.org/e/31 • http://vimcasts.org/e/32 • http://vimcasts.org/e/33 • http://vimcasts.org/e/34 •

    http://vimcasts.org/e/35
  170. Questions? http://baltimore.org/submit-a-talk.html