├── README.md └── nerdtree_plugin └── NERDTreeFugitive.vim /README.md: -------------------------------------------------------------------------------- 1 | #NERDtree-Fugitive 2 | 3 | ######A plugin that adds git and vim-fugitive functionality to NERDtree 4 | 5 | Very straight forward implementation that uses the NERDTree menu api to make calls to vim-fugitive. This plugin requires both [scrooloose/nerdtree](https://github.com/scrooloose/nerdtree) and [tpope/vim-fugitive](https://github.com/tpope/vim-fugitive). Though you could also open the file and perform vim-fugitive calls from the commandline or via shortcuts, I find it useful to view the directory structure and be able to perform git functions directly from a GUI menu, especially with the xuyuanp/nerdtree-git-plugin for visual markers. 6 | 7 | I only worked on this for a few hours, so let me know if there are any bugs or features that could be improved/added. I'm also planning something similair for Cntrp 8 | 9 | ###Installation 10 | Install it with Vundle by putting 11 | `Bundle “low-ghost/nerdtree-fugitive” 12 | in your .vimrc.bundles or equivalent file, source your vimrc and run :BundleInstall in vim. Similar with Plug and NeoBundle. 13 | 14 | ###Additional 15 | Works well with Xuyuanp/nerdtree-git-plugin, which provides visual markers of file status. 16 | 17 | ###What it does: 18 | Adds a (g)it menu to the NERDtree menu, entered by toggling NERDtree and hitting ‘m’ then ‘g’ 19 | 20 | ###The Menu 21 | 22 | (a)dd - Git add without opening the file 23 | (w)rite - open file and Gwrite 24 | (l)og - open file and go to fugitive log window 25 | (d)iff - open diff or merge conflict tool 26 | (o)pen a version from another branch 27 | (r)emove - open buffer then Gremove it and destroy the buffer 28 | (b)lame - open file and go to Gblame quickfix window 29 | (g)rep - search this file with normal grep 30 | Ggr(e)p - search the full repo with git grep 31 | (s)tatus - jump to file in fugitive status window 32 | 33 | ## Credits 34 | 35 | * [scrooloose](https://github.com/scrooloose): NERDtree and its API 36 | * [tpope](https://github.com/tpope/vim-fugitive): vim-fugitive and Git wrapper 37 | * [Xuyuanp](https://github.com/Xuyuanp/nerdtree-git-plugin): optional visual elements 38 | -------------------------------------------------------------------------------- /nerdtree_plugin/NERDTreeFugitive.vim: -------------------------------------------------------------------------------- 1 | "git dir is b:git_dir 2 | 3 | if exists("g:loaded_nerdtree_fugitive") 4 | finish 5 | endif 6 | 7 | let g:loaded_nerdtree_fugitive = 1 8 | 9 | call NERDTreeAddMenuSeparator({ 10 | \ 'isActiveCallback': 'NERDTreeFugitiveEnabled'}) 11 | 12 | let gitSubMenu = NERDTreeAddSubmenu({ 13 | \ 'text': '(g)it', 14 | \ 'isActiveCallback': 'NERDTreeFugitiveEnabled', 15 | \ 'shortcut': 'g', 16 | \ 'scope': 'FileNode'}) 17 | 18 | call NERDTreeAddMenuItem({ 19 | \ 'text': '(a)dd - Git add without opening the file', 20 | \ 'shortcut': 'a', 21 | \ 'parent': gitSubMenu, 22 | \ 'scope': 'FileNode', 23 | \ 'callback': 'NERDTreeFugitiveAdd' }) 24 | 25 | call NERDTreeAddMenuItem({ 26 | \ 'text': '(w)rite - open file and Gwrite', 27 | \ 'shortcut': 'w', 28 | \ 'parent': gitSubMenu, 29 | \ 'scope': 'FileNode', 30 | \ 'callback': 'NERDTreeFugitiveWrite' }) 31 | 32 | call NERDTreeAddMenuItem({ 33 | \ 'text': '(l)og - open file and go to fugitive log window', 34 | \ 'shortcut': 'l', 35 | \ 'parent': gitSubMenu, 36 | \ 'scope': 'FileNode', 37 | \ 'callback': 'NERDTreeFugitiveLog' }) 38 | 39 | call NERDTreeAddMenuItem({ 40 | \ 'text': '(d)iff - open diff or merge conflict tool', 41 | \ 'shortcut': 'd', 42 | \ 'parent': gitSubMenu, 43 | \ 'scope': 'FileNode', 44 | \ 'callback': 'NERDTreeFugitiveDiff' }) 45 | 46 | call NERDTreeAddMenuItem({ 47 | \ 'text': '(o)pen a version from another branch', 48 | \ 'shortcut': 'o', 49 | \ 'parent': gitSubMenu, 50 | \ 'callback': 'NERDTreeFugitiveOpen' }) 51 | 52 | call NERDTreeAddMenuItem({ 53 | \ 'text': '(r)emove - open buffer then Gremove it and destroy the buffer', 54 | \ 'shortcut': 'r', 55 | \ 'parent': gitSubMenu, 56 | \ 'scope': 'FileNode', 57 | \ 'callback': 'NERDTreeFugitiveRemove' }) 58 | 59 | call NERDTreeAddMenuItem({ 60 | \ 'text': '(b)lame - open file and go to Gblame quickfix window', 61 | \ 'shortcut': 'b', 62 | \ 'parent': gitSubMenu, 63 | \ 'scope': 'FileNode', 64 | \ 'callback': 'NERDTreeFugitiveBlame' }) 65 | 66 | call NERDTreeAddMenuItem({ 67 | \ 'text': '(g)rep - search this object with normal grep', 68 | \ 'shortcut': 'g', 69 | \ 'parent': gitSubMenu, 70 | \ 'scope': 'FileNode', 71 | \ 'callback': 'NERDTreeFugitiveGrep' }) 72 | 73 | call NERDTreeAddMenuItem({ 74 | \ 'text': 'Ggr(e)p - search the full repo', 75 | \ 'shortcut': 'e', 76 | \ 'parent': gitSubMenu, 77 | \ 'scope': 'FileNode', 78 | \ 'callback': 'NERDTreeFugitiveGgrep' }) 79 | 80 | call NERDTreeAddMenuItem({ 81 | \ 'text': '(s)tatus - jump to file in fugitive status window', 82 | \ 'shortcut': 's', 83 | \ 'parent': gitSubMenu, 84 | \ 'callback': 'NERDTreeFugitiveStatus' }) 85 | 86 | function! NERDTreeFugitiveEnabled() 87 | let p = g:NERDTreeFileNode.GetSelected().path 88 | return !p.isDirectory 89 | endfunction 90 | 91 | function! s:getPath() 92 | let n = g:NERDTreeFileNode.GetSelected() 93 | let g:ntfLastNode = n.path.str() 94 | return g:ntfLastNode 95 | endfunction 96 | 97 | function! NERDTreeFugitiveWrite() 98 | let p = s:getPath() 99 | call g:NERDTree.Close() 100 | exe "e! " . p | Gwrite | exe "e " . p 101 | endfunction 102 | 103 | function! NERDTreeFugitiveAdd() 104 | let p = s:getPath() 105 | exe "silent Git add " . p 106 | endfunction 107 | 108 | function! NERDTreeFugitiveRemove() 109 | let p = s:getPath() 110 | call g:NERDTree.Close() 111 | exe "e!" . p | Gremove 112 | endfunction 113 | 114 | function! NERDTreeFugitiveStatus() 115 | let p = fnamemodify(s:getPath(), ":t") 116 | call g:NERDTree.Close() 117 | exe "Gstatus" | exe "/" . p 118 | endfunction 119 | 120 | function! NERDTreeFugitiveLog() 121 | let p = s:getPath() 122 | call g:NERDTree.Close() 123 | exe "e!" . p | silent Glog | copen 124 | endfunction 125 | 126 | function! NERDTreeFugitiveBlame() 127 | let p = s:getPath() 128 | call g:NERDTree.Close() 129 | exe "e!" . p | silent Gblame 130 | endfunction 131 | 132 | function! NERDTreeFugitiveDiff() 133 | let p = s:getPath() 134 | call g:NERDTree.Close() 135 | exe "e!" . p | silent Gdiff 136 | endfunction 137 | 138 | function! NERDTreeFugitiveGgrep() 139 | echo "=======================================\n" 140 | echo "complete git grep command with arguments and search terms:\n" 141 | let cmd = input(':Ggrep ') 142 | call g:NERDTree.Close() 143 | if cmd != '' 144 | exe ':silent Ggrep ' . cmd | copen 145 | else 146 | echo "Aborted" 147 | endif 148 | endfunction 149 | 150 | function! NERDTreeFugitiveGrep() 151 | let p = s:getPath() 152 | echo "=======================================\n" 153 | echo "complete grep command with options and arguments (filename appended):\n" 154 | let cmd = input(':grep ') 155 | call g:NERDTree.Close() 156 | if cmd != '' 157 | exe ":silent grep " . cmd . " " . p | copen 158 | else 159 | echo "Aborted" 160 | endif 161 | endfunction 162 | 163 | function! NERDTreeFugitiveOpen() 164 | let p = s:getPath() 165 | echo "=======================================\n" 166 | let cmd = input('Branch name: ') 167 | call g:NERDTree.Close() 168 | if cmd != '' 169 | exe ':silent Gedit ' . cmd . ":" . p 170 | else 171 | echo "Aborted" 172 | endif 173 | endfunction 174 | --------------------------------------------------------------------------------