Skip to content
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

Netrw fails to open file with long filename #10055

Closed
xudongzheng opened this issue Mar 31, 2022 · 3 comments
Closed

Netrw fails to open file with long filename #10055

xudongzheng opened this issue Mar 31, 2022 · 3 comments

Comments

@xudongzheng
Copy link

xudongzheng commented Mar 31, 2022

Steps to reproduce

Add let g:netrw_liststyle = 1 to .vimrc

Create a directory with several files like in the following screenshot

Screen Shot 2022-03-31 at 13 22 27

  • 123456789012345678901234567890 and 1234567890123456789012345678901 open correctly
  • 12345678901234567890123456789012 does not open correctly. Vim opens the 12345678901234567890123456789012 29 Thu Mar 31 13:17:54 2022 file instead. Same problem with 123456789012345678901234567890123.

Expected behaviour

File 12345678901234567890123456789012 should open correctly.

Version of Vim

8.2.4113

Environment

Operating System: macOS 12.3 (I'm running the macOS default version of Vim)

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Feb 12 2022 04:26:50)
macOS version - x86_64
Included patches: 1-4113
Compiled by root@apple.com

Logs and stack traces

No response

@cecamp
Copy link
Collaborator

cecamp commented Mar 31, 2022

See :help g:netrw_maxfilenamelen and set it to a larger number.

@cecamp cecamp closed this as completed Mar 31, 2022
@chrisbra
Copy link
Member

I think there is some room for improvements. If I read the code correctly, when pressing Enter, netrw is trying to determine the filename by using:

let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')

If I read the regexp correctly, this expects at least 2 spaces after the filename. So we would need to fix this in s:LocalListing()

let longfile= printf("%-".(g:netrw_maxfilenamelen+1)."s",pfile)

By adding 2.

And finally to make it work, I think this line here:

if get(g:, 'netrw_dynamic_maxfilenamelen', 0)

should be 1, so that it adds additional spaces by default. (if not, it won't automatically adjust g:netrw_maxfilenamelen)

Altogether this patch seems to fix it:

diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim
index 7d1a35c1a..395ff0243 100644
--- a/runtime/autoload/netrw.vim
+++ b/runtime/autoload/netrw.vim
@@ -11017,7 +11017,7 @@ fun! s:LocalListing()
 "  call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
 "  call Decho("before while: filelist  =".string(filelist),'~'.expand("<slnum>"))

-  if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
+  if get(g:, 'netrw_dynamic_maxfilenamelen', 1)
    let filelistcopy           = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
    let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
 "   call Decho("dynamic_maxfilenamelen: filenames             =".string(filelistcopy),'~'.expand("<slnum>"))
@@ -11089,7 +11089,7 @@ fun! s:LocalListing()
     if g:netrw_sizestyle =~# "[hH]"
      let sz= s:NetrwHumanReadable(sz)
     endif
-    let longfile= printf("%-".(g:netrw_maxfilenamelen+1)."s",pfile)
+    let longfile= printf("%-".(g:netrw_maxfilenamelen+2)."s",pfile)
     let pfile   = longfile.sz." ".strftime(g:netrw_timefmt,getftime(filename))
 "    call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
    endif

@chrisbra chrisbra reopened this Mar 31, 2022
@cecamp
Copy link
Collaborator

cecamp commented Apr 2, 2022

And the next complaint will be that for 33+ character filenames that the long listing display is uneven. I suppose that that's better than picking up an incorrectly named file, so I'll include it.

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

No branches or pull requests

4 participants