Skip to content

Improve handling obsolete buffers when renaming or deleting a file via the NERDTree 'm' menu #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 18, 2012

Conversation

AndreyKozlov1984
Copy link
Contributor

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

Previously when you delete or moved a file via
md or mm commands the NERDTree was asking you about what to do
with the remaining buffer of the just deleted or moved file. I
always press 'y' in this cases so I've decided to add a new parameter,
NERDTreeAutoDeleteBuffer which you can set to 1 in order to skip
this confirmation.
If you are renaming a file via the mm hotkey and it is already opened then all
tabs and windows containing the old file will be replaced with a
new file. Current tab and windows structure is not changed anymore

If you are deleting a file via the md hotkey and it is already open, i.e.
presents in buffer lists then a buffer will be removed but a window and tab
will be kept with a ':enew' file
@twe4ked
Copy link

twe4ked commented Oct 18, 2012

@ZeusTheTrueGod this is awesome, any chance of reviewing this @scrooloose?

scrooloose added a commit that referenced this pull request Oct 18, 2012
Improve handling obsolete buffers when renaming or deleting a file via the NERDTree 'm' menu
@scrooloose scrooloose merged commit 3e44d4e into preservim:master Oct 18, 2012
@scrooloose
Copy link
Collaborator

Sweet, looks good. Cheers :)

@twe4ked
Copy link

twe4ked commented Oct 18, 2012

Thanks @ZeusTheTrueGod and @scrooloose.

👍

@yoran-brault
Copy link

That's great thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants