lambdalisue / vim-fern

🌿 General purpose asynchronous tree viewer written in Pure Vim script
MIT License
1.29k stars 49 forks source link

E13 "file exists, add ! to override" after "move/rename" on Vim 8.2 #165

Closed nickjj closed 4 years ago

nickjj commented 4 years ago

Hi,

It's reproduceable.

100% of the time after I move a file using fern, when I save the file with :w it will error out with E13 file exists, add ! to override. Then I save the file with w! and after that I don't have issues as long as I don't rename the file again.

Perhaps this has to do with the recent issue / PR related to removing the old file in the buffer and swapping it with the newly renamed file?

Also, I'm finding that if I move a file to a different directory that exists with fern and I save and get that error, fern sometimes tries to reveal the old location instead of the new one when toggling fern. I can't figure out how to reproduce this one yet but it happens a lot. It might be related so I'm including that info here.

lambdalisue commented 4 years ago

https://github.com/lambdalisue/fern.vim/issues/155

Are you sure the fern is the latest?

lambdalisue commented 4 years ago

Also, I'm finding that if I move a file to a different directory that exists with fern and I save and get that error, fern sometimes tries to reveal the old location instead of the new one when toggling fern. I can't figure out how to reproduce this one yet but it happens a lot. It might be related so I'm including that info here.

I'm sorry but I don't get what you mean. Please create a new issue with a little bit easier English.

nickjj commented 4 years ago

Are you sure the fern is the latest?

Yes, latest master. I just pulled it a few seconds ago to be sure.

lambdalisue commented 4 years ago

Could not reproduce with

" vim -u ~/.vim/vimrc.min
if has('vim_starting')
  set nocompatible
endif

nnoremap ; :
nnoremap : ;

set packpath=
set runtimepath+=~/.config/nvim/pack/minpac/start/fern.vim

filetype plugin indent on
syntax on
$ touch foo
  1. vim -u ~/.vim/vimrc.min
  2. :e foo
  3. :Fern .
  4. Cursor foo and hit a
  5. Type move then bar (move foo to bar)
  6. :e bar
  7. :w

So please provide minimal vimrc and reproducible steps.

nickjj commented 4 years ago

Did you try it on Vim 8.2?

And did you try it after toggling / revealing the file instead of manually selecting it?

lambdalisue commented 4 years ago

Please provide a step by step procedure. It's tough for me to find a correct procedure from a long English paragraph.

lambdalisue commented 4 years ago

Did you try it on Vim 8.2?

This is it!

nickjj commented 4 years ago

Fern related config:

" Disable netrw.
let g:loaded_netrw  = 1
let g:loaded_netrwPlugin = 1
let g:loaded_netrwSettings = 1
let g:loaded_netrwFileHandlers = 1

augroup my-fern-hijack
  autocmd!
  autocmd BufEnter * ++nested call s:hijack_directory()
augroup END

function! s:hijack_directory() abort
  let path = expand('%:p')
  if !isdirectory(path)
    return
  endif
  bwipeout %
  execute printf('Fern %s', fnameescape(path))
endfunction

" Custom settings and mappings.
let g:fern#disable_default_mappings = 1

noremap <silent> <Leader>f :Fern . -drawer -reveal=% -toggle -width=35<CR><C-w>=

function! FernInit() abort
  nmap <buffer><expr>
        \ <Plug>(fern-my-open-expand-collapse)
        \ fern#smart#leaf(
        \   "\<Plug>(fern-action-open:select)",
        \   "\<Plug>(fern-action-expand)",
        \   "\<Plug>(fern-action-collapse)",
        \ )
  nmap <buffer> <CR> <Plug>(fern-my-open-expand-collapse)
  nmap <buffer> <2-LeftMouse> <Plug>(fern-my-open-expand-collapse)
  nmap <buffer> n <Plug>(fern-action-new-path)
  nmap <buffer> d <Plug>(fern-action-remove)
  nmap <buffer> m <Plug>(fern-action-move)
  nmap <buffer> M <Plug>(fern-action-rename)
  nmap <buffer> h <Plug>(fern-action-hidden-toggle)j
  nmap <buffer> r <Plug>(fern-action-reload)
  nmap <buffer> k <Plug>(fern-action-mark-toggle)j
  nmap <buffer> b <Plug>(fern-action-open:split)
  nmap <buffer> v <Plug>(fern-action-open:vsplit)
  nmap <buffer><nowait> < <Plug>(fern-action-leave)
  nmap <buffer><nowait> > <Plug>(fern-action-enter)
endfunction

augroup FernGroup
  autocmd!
  autocmd FileType fern call FernInit()
augroup END

Test set up:

mkdir -p /tmp/testfern/ok \
  &&  cd /tmp/testfern \
  && touch ok/1

vim .

Within Vim:

:e ok/1
Leader+f
m
Rename the file from `1` to `2`
Focus the new `2` file in the buffer
:w
Notice the E13 error
lambdalisue commented 4 years ago

It seems BufWriteCmd is not used in Vim 8.2. I've no idea why.

https://github.com/lambdalisue/fern.vim/blob/master/autoload/fern/scheme/file/bufutil.vim#L42

lambdalisue commented 4 years ago

https://github.com/vim/vim/issues/5807 https://github.com/vim-jp/issues/issues/1337#issuecomment-600948187

lambdalisue commented 4 years ago

" 7.1.172 https://github.com/vim/vim/commit/11717bb0a1275f1e270396aeb1df92d973d4d068 " 8.2.0404 https://github.com/vim/vim/commit/18a2b87ca27c378a555b20f14a284d2ce3511427 " 8.2.0474 https://github.com/vim/vim/commit/0fff44152d06e6b662ad4bef172af07a041d2f3f

lambdalisue commented 4 years ago

when set allows you to rename a file and then have the newly renamed file replace the old file in the buffer and retain things like syntax highlighting, jumps, etc.

https://github.com/lambdalisue/fern.vim/issues/129

I thought NERDTree retain the (modified & unsaved) content or whatever but it seems they just open a new file and close the old buffer. It's simple. We can do that easily.

https://github.com/preservim/nerdtree/blob/96e247ba7488af1e71d0facfc68aba37e750298c/nerdtree_plugin/fs_menu.vim#L139-L162

In contrast to that, current fern retains modified & unsaved content or undo history or whatever while it uses exactly same buffer. So it can be an advantage if I could make it.

lambdalisue commented 4 years ago

OK. Let's remove that feature first. https://github.com/lambdalisue/fern.vim/pull/167

I think I've found a workaround. Please try the following @nickjj https://github.com/lambdalisue/fern.vim/pull/168

nickjj commented 4 years ago

I haven't done an extensive test but in the repeatable work flow listed above, E13 no longer occurs and the file renames / saves correctly with the issue165-v2 branch. Nice work!