I know about
:only and Ctrl+wo.
But I want to keep NERDTree window untouched. Is there a way to achieve it?
This solution only works with vim 8+
You can add this to your
function! OnlyAndNerdtree() let currentWindowID = win_getid() windo if win_getid() != currentWindowID && &filetype != 'nerdtree' | close | endif endfunction command! Only call OnlyAndNerdtree()
The function gets the id of the current window with
win_getid() then it uses
windo do iterate through all of the windows and execute code following it.
The code test if the id of the window is different than the id of the current windo and if the filetype of its buffer is different than
nerdtree. If both of the conditions are met, the window is closed.
And the last line creates the command
:Only which calls the function.
win_getid() was only introduced in Vim 8, with previous versions of Vim a workaround must be possible wit
winnr() but it would probably not be as easy as with
win_getid() especially because when a window is closed, the number of the other windows are updated.
"buffer only nnoremap <leader>bo :call te#tools#buf_only('', '')<cr>