Netrw is unable to open symlinked files in tree view. In other views it works fine. Verified without local .vimrc.
Repro:
$ cd ~/tmp
$ echo “xxx” > baz.txt
$ ln -s baz.txt link.txt
$ vim
:Ex then i until tree view appearsThis results in status line showing ~/tmp/link.txt/link.txt [Permission Denied], and file is not opened.
OS: macOS 10.13.1
Terminal: iTerm2 3.1.5
netrw version v162:
Oct 17, 2017 * (Adam Faryna) reported that gn (|netrw-gn|)
did not work on directories in the current
tree
~$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 19 2017 18:04:47)
macOS version
Included patches: 1-1300
Compiled by Homebrew
Huge version without GUI. Features included (+) or not (-):
+acl +farsi +mouse_netterm +tag_binary
+arabic +file_in_path +mouse_sgr +tag_old_static
+autocmd +find_in_path -mouse_sysmouse -tag_any_white
-autoservername +float +mouse_urxvt -tcl
-balloon_eval +folding +mouse_xterm +termguicolors
-browse -footer +multi_byte +terminal
++builtin_terms +fork() +multi_lang +terminfo
+byte_offset -gettext -mzscheme +termresponse
+channel -hangul_input +netbeans_intg +textobjects
+cindent +iconv +num64 +timers
-clientserver +insert_expand +packages +title
+clipboard +job +path_extra -toolbar
+cmdline_compl +jumplist +perl +user_commands
+cmdline_hist +keymap +persistent_undo +vertsplit
+cmdline_info +lambda +postscript +virtualedit
+comments +langmap +printer +visual
+conceal +libcall +profile +visualextra
+cryptv +linebreak +python +viminfo
+cscope +lispindent -python3 +vreplace
+cursorbind +listcmds +quickfix +wildignore
+cursorshape +localmap +reltime +wildmenu
+dialog_con +lua +rightleft +windows
+diff +menu +ruby +writebackup
+digraphs +mksession +scrollbind -X11
-dnd +modify_fname +signs -xfontset
-ebcdic +mouse +smartindent -xim
+emacs_tags -mouseshape +startuptime -xpm
+eval +mouse_dec +statusline -xsmp
+ex_extra -mouse_gpm -sun_workshop -xterm_clipboard
+extra_search -mouse_jsbterm +syntax -xterm_save
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o vim -lncurses -liconv -framework AppKit -L/usr/local/lib -llua -mmacosx-version-min=10.12 -fstack-protector-strong -L/usr/local/lib -L/usr/local/Cellar/perl/5.26.1/lib/perl5/5.26.1/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc -F/usr/local/opt/python/Frameworks -framework Python -lruby.2.4.2 -lobjc
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
Also confirmed on Debian Stretch
Have you tried the latest Version of netrw?
The link looks wrong.
Maybe #2783 (comment)
oops, yes sorry for the wrong link.
I have the same bug. Is there any solution for this?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
cc @cecamp
I have the same bug. Is there any solution for this?
Try to write the following code in a file (e.g. /tmp/fix.vim):
vim9script const NETRW_DIR: string = $HOME .. '/.vim/pack/mine/start/netrw' mkdir(NETRW_DIR, 'p') for file in glob($VIMRUNTIME .. '/**/*netrw*.vim', false, true) var copy_file: string = file->substitute($VIMRUNTIME, NETRW_DIR, '') mkdir(copy_file->fnamemodify(':h'), 'p') readfile(file)->writefile(copy_file) endfor var patch: list<string> =<< DATA From 9e2b8779cdd2bd511b621637e2b31beaf19dffb7 Mon Sep 17 00:00:00 2001 From: joeran (Vim Github Repository) Date: Tue, 6 Nov 2018 20:11:27 +0100 Subject: [PATCH] runtime/autoload/netrw: Correct symlink handling in tree liststyle Fixes #2386 #445 The actual implementation of s:NetrwTreeDir causes symlinks to be handled wrong in case the current netrw_liststyle is the tree view ('3'). This happens for file and for directory symlinks, which are edited itself. --- runtime/autoload/netrw.vim | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim index 76485c2f3815..cf80cc55516c 100644 --- a/runtime/autoload/netrw.vim +++ b/runtime/autoload/netrw.vim @@ -8878,7 +8878,7 @@ fun! s:NetrwTreeDir(islocal) " call Decho("treedir<".treedir.">",'~'.expand("<slnum>")) elseif curline =~ '@$' " call Decho("handle symbolic link from current line",'~'.expand("<slnum>")) - let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e')) + let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e')) " call Decho("treedir<".treedir.">",'~'.expand("<slnum>")) else " call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>")) @@ -8900,21 +8900,17 @@ fun! s:NetrwTreeDir(islocal) " call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>")) endif -" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>")) - let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1','')) -" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>")) - - " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop -" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir)) -" let newdir = w:netrw_treetop.'/'.potentialdir -" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>")) -" let treedir = s:NetrwTreePath(newdir) -" let w:netrw_treetop = newdir -" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>")) -" else + if a:islocal && curline =~ '@$' +" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>")) + if isdirectory(s:NetrwFile(potentialdir)) + " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop...at least for directories + let treedir = w:netrw_treetop.'/'.potentialdir.'/' + let w:netrw_treetop = treedir + endif + else " call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>")) let treedir = s:NetrwTreePath(w:netrw_treetop) -" endif + endif endif " sanity maintenance: keep those //s away... DATA system('cd ' .. NETRW_DIR .. ' && patch -p2', patch)
Start Vim like this (to source the fix):
vim -Nu NONE -S /tmp/fix.vim
This fix.vim file should automatically do 2 things for you:
~/.vim/pack/mine/start/netrw/, but you can change it to whatever you want, as long as :packadd can find it)—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
![]()
version 8.2.4113
git difftool set to vimdiff
git difftool -d branch1 head # head branch will create soft link file to local
then error will product
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Hello, Lacygoill:
Your patch didn't apply cleanly, and what I did manually won't work in debug mode, so I'd like to discuss it with you via email. Would you send me a note? (you can find my email at the top of netrw.vim)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
i write some code to temporarily solve this problem
add this code to .vimrc
" ============================================ Netrw tree =================================================
hi! link netrwMarkFile Search "高亮显示标记的文件
let g:netrw_localcopydircmd = 'cp -r' "复制目录时用的命令
let g:netrw_bufsettings = 'noma nomod nu relativenjmber nobl nowrap ro'
let g:netrw_list_hide=''
let g:netrw_browse_split=4
let g:netrw_altv=1
let g:netrw_liststyle=3
let g:netrw_keepdir = 0
if &diff
let g:netrw_banner = 0
else
let g:netrw_banner = 0
endif
function! NetrwExpandTree()
if &ft != 'netrw'
echo "not netrw filetype"
return
endif
while 1
let regex = '\v(^(\| )+)\w+\/$(.*\n^\1\|)@!'
let result = search(regex)
if result == 0
return
endif
execute "normal \<CR>"
endwhile
endfunction
function! Locat2parentDir()
" 如果不是文件直接返回 \|[ ] 开头,文件名不是\/结尾
let currentLine = getline(".")
let pattern = '\v^(%(\| )+)'
"echo currentLine
if match(currentLine,pattern) <0
return
endif
" 缩进
let identation = matchlist(currentLine,pattern)[1]
let parentDirIdentation = substitute(identation,'\v^(.{0,})\| $','\1','')
"echo parentDirIdentation
let parentDirPattern = '\v^'. substitute(parentDirIdentation , '\v\|' , '\\|' , 'g') . '[^ \|]+\/'
"echo parentDirPattern
let jpParentResult = search(parentDirPattern,'b')
return
endfunction
function! NetrwOpenFileToTab()
" 如果不是文件直接返回 \|[ ] 开头,文件名不是\/结尾
let currentLine = getline(".")
let pattern = '\v^(%(\| )+)([^ ]+)[^$]*%($%(\/)@<!)'
"echo currentLine
if match(currentLine,pattern) <0
echo "not a file "
return
endif
" 文件名
let fileName = matchlist(currentLine,pattern)[2]
" 如果是软连接,文件名去掉尾部的@
let isSoftLink = match(fileName,'\v^.+\@(\s)@=') == 0
if isSoftLink
let fileName = substitute(fileName,'\v(^.+)\@%(\s)@=','\1','')
endif
"echo fileName
" 跳转到目录节点折叠再展开,keepdir=0的情况下,这个操作会改变pwd,展开后再跳回原来的位置 echo $line
let ln = line(".")
call Locat2parentDir()
execute "normal \<CR>\<CR>"
execute "normal :" . ln . "\<CR>"
let fullfilename = substitute(system("pwd"),'\v^(%(.\n@!)+.)','\1\/' . fileName ,'')
"echo fullfilename
execute "normal :tabnew " . fullfilename . "\<CR>"
return
" 如果已经有tab了,切换到tab垂直分割读路径,否则tabnew读路径文件, 最后切回来原来的tab
endfunction
au FileType netrw nnoremap <buffer> <silent> et :call NetrwExpandTree()<CR>
au FileType netrw nnoremap <buffer> <silent> t :call NetrwOpenFileToTab()<CR>
au FileType netrw nnoremap <buffer> <silent> zc :call Locat2parentDir()<CR>
au FileType netrw hi CursorLine gui=underline
au FileType netrw au BufEnter <buffer> hi CursorLine gui=underline
au FileType netrw au BufLeave <buffer> hi clear CursorLine
now in netrw , you can do this :
zc to jump parent node
et to expand all node
t to open file and soft link file
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
if you think you can fix it, please contact @cecamp (contact info mentioned at the top of the netrw file) and share some code/patch which fixes the issue.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
if you think you can fix it, please contact @cecamp (contact info mentioned at the top of the netrw file) and share some code/patch which fixes the issue.
i just test modify .vimrc to fix this logic erro when using gitdiff + liststyle == tree , i am not able to chang source because i have never cretated vim plugin , this is foreign to me
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Hello, Lacygoill:
Your patch didn't apply cleanly, and what I did manually won't work in debug mode, so I'd like to discuss it with you via email. Would you send me a note? (you can find my email at the top of netrw.vim)
Unfortunately, I would not be able to help. I don't know this code well enough. The patch I suggested was simply copied from this pull request. Let me ping @JoeKar, the author of the patch. They might be able to provide an updated patch.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Hey folks,
it wouldn't be a big wonder that the patch provided with PR #3609 doesn't apply any longer without trouble after more than 4 (in words: four) years...
@cecamp
I tried to contact you directly via the NdrO...@ScampbellPfamily.AbizM-NOSPAM (yes, I really removed all "NOSPAMs" ;) ) at 06.11.2018, 21:42, but unfortunately there wasn't any reply till now:
Hello Mr. Campbell,
I hope you're fine.
I discovered, as others too, some issues handling symlink in NETRWs tree view. They're caused by a wrong resolve of the links into the treedir in the s:NetrwTreeDir function...at least from my point of view.
Attached you can find a git-formatted patch to "solve" these issues. The commit is available at GitHub too:
JoeKar@9e2b877I tried your beta v163b, but the issue wasn't neither solved with it even though the behavior was slightly different. With the beta I was able to open the links, but the linked target (after the "-->") was renamed as well and I need to press ENTER twice.
Maybe there is even a better way to solve that, but I didn't found it yet. At least there is something to review now.
I wish you a nice day.
Best regards
Since I don't use VIM and netrw that often it would take me some time to get into it too.
Let me see, what I can do...
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@JoeKar I am new to git and github and am confused what the old source branch of the PR is and how to get it. I'm also not familiar with the standard modes of correspondence between maintainers in the project, but have read that cecamp prefers e-mail but don't want to step on any toes yet.
It doesn't appear that there has been a patch of this on the main branch yet since the issue is still opened and I face the same problem. Can you provide an update here to let us know if cecamp has responded to your e-mail regarding this patch, what might be expected for the patch to be accepted to the main branch yet still, and help me to apply the patch to vim?
Regards,
Devon
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
I am not exactly sure, but the following patch seems to resolve it:
diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim index 0508dcae3..850e5a40f 100644 --- a/runtime/autoload/netrw.vim +++ b/runtime/autoload/netrw.vim @@ -9476,7 +9476,7 @@ fun! s:NetrwTreeDir(islocal) " call Decho("treedir<".treedir.">",'~'.expand("<slnum>")) elseif curline =~ '@$' " call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
- let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e')) + let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e')) " call Decho("treedir<".treedir.">",'~'.expand("<slnum>")) else " call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
@@ -9501,7 +9501,6 @@ fun! s:NetrwTreeDir(islocal)
" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
- let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
@@ -9514,8 +9513,15 @@ fun! s:NetrwTreeDir(islocal)
" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
" else
" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
- let treedir = s:NetrwTreePath(w:netrw_treetop)
-" endif
+ if a:islocal && curline =~ '@$'
+ if isdirectory(s:NetrwFile(potentialdir))+ let treedir = w:netrw_treetop.'/'.potentialdir.'/' + let w:netrw_treetop = treedir + endif + else
+ let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1','')) + let treedir = s:NetrwTreePath(w:netrw_treetop) + endif endif " call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
I am not exactly sure, but the following patch seems to resolve it
What version of the project is that for?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Closed #2386 as completed via 56b7da3.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()