Last active
November 10, 2022 00:01
-
-
Save mheiber/fc93b8039f38c4999b92ab77d454c16f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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