vim: nerdtree autostart fixes - dotfiles - arsenal of config files, ready to be cloned in new (virtual) machines.
HTML git clone git://git.drkhsh.at/dotfiles.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
---
DIR commit ca7ebda91d9378d2a5833c42dd86ba0e94ff88b4
DIR parent 7fcc6190b60e1825991d9e9a4354b3afd3cc02cc
HTML Author: drkhsh <me@drkhsh.at>
Date: Mon, 23 Jan 2023 21:19:21 +0100
vim: nerdtree autostart fixes
Diffstat:
M vim/.vimrc | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
---
DIR diff --git a/vim/.vimrc b/vim/.vimrc
@@ -82,9 +82,22 @@ nnoremap <C-n> :NERDTree<CR>
nnoremap <C-t> :NERDTreeToggle<CR>
nnoremap <C-f> :NERDTreeFind<CR>
+
" █▓▒░ nerdtree: autostart; if a file is specified, move the cursor to its window.
+"autocmd StdinReadPre * let s:std_in=1
+"autocmd VimEnter * NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif
+
+" █▓▒░ nerdtree: start when Vim is started without file arguments.
autocmd StdinReadPre * let s:std_in=1
-autocmd VimEnter * NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif
+autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif
+
+" █▓▒░ nerdtree: start when Vim starts with a directory argument.
+autocmd StdinReadPre * let s:std_in=1
+autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') |
+ \ execute 'NERDTree' argv()[0] | wincmd p | enew | execute 'cd '.argv()[0] | endif
+
+" █▓▒░ nerdtree: exit Vim if NERDTree is the only window remaining in the only tab.
+autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" █▓▒░ vim-markdown: Folding
let g:vim_markdown_folding_disabled = 1