Skip to content

Instantly share code, notes, and snippets.

@mheiber
Last active November 10, 2022 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mheiber/fc93b8039f38c4999b92ab77d454c16f to your computer and use it in GitHub Desktop.
Save mheiber/fc93b8039f38c4999b92ab77d454c16f to your computer and use it in GitHub Desktop.
" usage: \b toggles the file browser, open to the directory containing the current file
nnoremap <leader>b :call ToggleNERDTree()<Cr>
function! ToggleNERDTree()
if !g:NERDTree.ExistsForTab() || !g:NERDTree.IsOpen()
if <SID>WindowFileExists()
:NERDTreeFind
else
let cwd = getcwd()
execute 'NERDTree ' . cwd
endif
else
:NERDTreeClose | :cclose
endif
endfunction
function! <SID>WindowFileExists()
let bn = getwininfo(win_getid())[0]['bufnr']
let b = filter(getbufinfo(), 'v:val["bufnr"] == ' . bn)[0]
return filereadable(b['name'])
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment