Skip to content

Commit

Permalink
Deal with some annoyances with how NERDTree is working
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Aug 10, 2010
1 parent c46d689 commit 8448f49
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions vimrc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -64,7 +64,24 @@ cmap <C-P> <C-R>=expand("%:p:h") . "/" <CR>
autocmd VimEnter * NERDTree autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p autocmd VimEnter * wincmd p
autocmd VimEnter * call s:CdIfDirectory(expand("<amatch>"))


" Disable netrw's autocmd, since we're ALWAYS using NERDTree
runtime plugin/netRwPlugin.vim
augroup FileExplorer
au!
augroup END

let g:NERDTreeHijackNetrw = 0

" If the parameter is a directory, cd into it
function s:CdIfDirectory(directory)
if isdirectory(a:directory)
call ChangeDirectory(a:directory)
endif
endfunction

" NERDTree utility function
function s:UpdateNERDTree() function s:UpdateNERDTree()
if exists("t:NERDTreeBufName") if exists("t:NERDTreeBufName")
if bufwinnr(t:NERDTreeBufName) != -1 if bufwinnr(t:NERDTreeBufName) != -1
Expand All @@ -74,6 +91,7 @@ function s:UpdateNERDTree()
endif endif
endfunction endfunction


" Utility functions to create file commands
function s:CommandCabbr(abbreviation, expansion) function s:CommandCabbr(abbreviation, expansion)
execute 'cabbrev ' . a:abbreviation . ' <c-r>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>' execute 'cabbrev ' . a:abbreviation . ' <c-r>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>'
endfunction endfunction
Expand All @@ -93,6 +111,7 @@ function s:DefineCommand(name, destination)
call s:CommandCabbr(a:name, a:destination) call s:CommandCabbr(a:name, a:destination)
endfunction endfunction


" Public NERDTree-aware versions of builtin functions
function ChangeDirectory(dir) function ChangeDirectory(dir)
execute "cd " . a:dir execute "cd " . a:dir
call s:UpdateNERDTree() call s:UpdateNERDTree()
Expand All @@ -117,11 +136,17 @@ function Remove(file)
endfunction endfunction


function Edit(file) function Edit(file)
if exists("b:NERDTreeRoot")
wincmd p
endif

execute "e " . a:file execute "e " . a:file
call ChangeDirectory(system("dirname " . a:file)) call ChangeDirectory(system("dirname " . a:file))
endfunction endfunction


" Define the NERDTree-aware aliases
call s:DefineCommand("cd", "ChangeDirectory") call s:DefineCommand("cd", "ChangeDirectory")
call s:DefineCommand("touch", "Touch") call s:DefineCommand("touch", "Touch")
call s:DefineCommand("rm", "Remove") call s:DefineCommand("rm", "Remove")
call s:DefineCommand("e", "Edit") call s:DefineCommand("e", "Edit")

0 comments on commit 8448f49

Please sign in to comment.