Skip to content

Commit 60e05fe

Browse files
committed
docs: update FAQ snippets containing quit command.
1 parent 6ad85ec commit 60e05fe

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.markdown

+18
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,24 @@ autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in
150150
151151
### How can I close Vim or a tab automatically when NERDTree is the last window?
152152
153+
Because of the changes in how Vim handles its `autocmd` and layout locking `quit` command is no longer available in Vim9 auto commands, Depending on which version you're running select one of these solutions.
154+
155+
__NeoVim users should be able to choose either one of them!__
156+
157+
#### Vim9
158+
159+
```vim
160+
" Exit Vim if NERDTree is the only window remaining in the only tab.
161+
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | call feedkeys(":quit\<CR>:\<BS>") | endif
162+
```
163+
---
164+
```vim
165+
" Close the tab if NERDTree is the only window remaining in it.
166+
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | call feedkeys(":quit\<CR>:\<BS>") | endif
167+
```
168+
169+
#### Vim8
170+
153171
```vim
154172
" Exit Vim if NERDTree is the only window remaining in the only tab.
155173
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

0 commit comments

Comments
 (0)