Improve handling obsolete buffers when renaming or deleting a file via the NERDTree 'm' menu #191
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I regularly rename and delete files via the NERDTree 'mm' and 'md' shortcuts. The default behaviour for renaming a node is to delete an old buffer. I made a change which replaces the old buffer with a new buffer(the renamed one) which also preserves your current tabs and windows layout. Previously renaming a file from a NERDTree with an active buffer in some window or tab leaded to closing this window or tab if a user agrees to delete the old buffer.
When a file is deleted via the 'md' shortcut I also preserve the windows and tabs layout when a user agrees to delete the old buffer.You see a ':enew' buffer in the window where the just removed file was. This change may be arguable when you have a dedicated tab for the just deleted file, currently it leaves the tab with an empty ':enew' buffer, probably deleting the tab with the only buffer may become a better idea
With this changes it seems quite reasonable to always delete an old buffer thus I've added a new option NERDTreeAutoDeleteBuffer which is turned off by default. When set it is assumed that you answer 'yes' on 'do you want to delete a buffer' or 'do you want to rename a buffer' questions after deleting or moving a node from the NERDTree menu.
I've tested this change with a 'hidden' option enabled and it works quite well in vim 7.3