I have NERDTree open all the time and sometimes I forget I have my cursor in there and I try to switch my main window to another buffer and it switched the NERDTree one, which get super annoying after doing it...

Is there any way to lock the NERDTree buffer from changing, or should I just map a command that sequentially takes care of resetting it?


I'm not aware of a native way to do this but you could set up an autocommand for NERDTree buffer only:

autocmd FileType nerdtree
    \ nnoremap <buffer> <C-O> <ESC> |
    \ nnoremap <buffer> <C-^> <ESC> |

You'd want to map like this whatever buffer swapping keys/commands that find yourself hitting regularly.

(For Normal mode mappings I'd use <ESC> because it beeps or flashes the screen when already in Normal mode...a nice warning. If you've silenced that or just prefer to do absolutely nothing you can replace it with <NOP>.)

  • @deltaskelta You're welcome. Note my update...I didn't have the multi-line syntax right. Now it's correct...tested just now.
    – B Layer
    Feb 7 '18 at 2:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.