Last active
November 26, 2021 11:03
-
-
Save davidmh/d97f230e354b016e135acaede4abc5a3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
" netrw | |
let g:netrw_banner = 0 " hide banner | |
let g:netrw_altv=1 " open splits to the right | |
let g:netrw_liststyle=3 " tree view | |
let g:netrw_list_hide=netrw_gitignore#Hide() | |
function! s:open_netrw() | |
" Grab the current file name | |
let file_name = expand("%:t") | |
" Open a 20-column left-side netrw explorer in the directory for the current | |
" file | |
20Lexplore %:h | |
let t:netrw_buffer_number = bufnr("%") | |
" find the file in the explorer | |
call search(file_name) | |
endfunction | |
function! s:toggle_netrw() | |
if exists("t:netrw_buffer_number") | |
let netrw_window_number = bufwinnr(t:netrw_buffer_number) | |
if netrw_window_number != -1 | |
let current_working_buffer = winnr() | |
" move to the netrw window | |
exec netrw_window_number . "wincmd w" | |
" close it | |
close | |
if current_working_buffer != netrw_window_number | |
" go back to the file | |
exec "silent! " . current_working_buffer . "wincmd w" | |
endif | |
unlet t:netrw_buffer_number | |
else | |
" was the explorer was closed manually? | |
call s:open_netrw() | |
endif | |
else | |
call s:open_netrw() | |
endif | |
endfunction | |
command! ToggleNetrwExplorer call s:toggle_netrw() | |
nnoremap <silent> \\ :ToggleNetrwExplorer<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment