nerdtree icon indicating copy to clipboard operation
nerdtree copied to clipboard

Add user choice to follow symlinks or keep them

Open terminatorul opened this issue 1 year ago • 4 comments

Add new option so users can choose to resolve symlinks or not.

Automatically resolving symlinks is not always the right choice, and is different from what Vim does, and can cause some issues for users when their directory changes unexpectedly.

Attached a (rather naive) patch that simply skips the call to Vim resolve() function if the option g:NERDTreeResolveSymLinks is disabled (v:false). The default option is v:true, to keep the original behavior of NERDTree, though I do not recommend it.

symlinks.zip

terminatorul avatar Feb 04 '24 17:02 terminatorul

Hi, Thanks for bringing this up. The reason behind resolving the symlinks in NERDTree was to show the symlink destination in the tree with the [name] -> [dest] format and provide the ability to follow the node in the tree on expanding it. There was PR #1367 for toggling the destination preview on or off. We can extend it so it can disable the whole symlink resolving. To make it easier on ourselves we can replace the toggle with a global variable to prevent it from changing constantly by the user in mid-session.

Until now there was no good reason for using #1367, But if we use it to keep symlinks unresolved it can be useful. Feel free to fork and modify that PR or create your own if you want to do it fresh.

rzvxa avatar Feb 05 '24 13:02 rzvxa

I think showing the symlinks (and junctions on Windows) is fine, as it will not cause problems to users, But replacing the symlink with the target, when changing directory (or loading a directory) or opening a file, is a different option.

I noticed somehow my simple patch obove does not affect how symlinks are displayed, but still prevents changing the original directory. So luckily it did exactly what I wanted.

terminatorul avatar Feb 06 '24 13:02 terminatorul

Maybe I'm wrong since I didn't use the patch I just read it, As far as I've seen NERDTree needs to resolve the path to knowing if a file is a symlink or not so I don't know how bypassing it wouldn't break the symlink destination. I need to run it to make sure, But I highly encourage you to create a PR for it.

rzvxa avatar Feb 06 '24 14:02 rzvxa

A PR addressing this issue may also resolve or help with #1339 and #1352.

rzvxa avatar Feb 07 '24 13:02 rzvxa