leafOfTree/vim-vue-plugin

Loading views automatically with autocmd fails

realtradam opened this issue · 4 comments

I have an augroup set up that automatically saves and loads the cursor position as well as which folds were open/closed whenever I enter and leave a buffer. Saving the view this way works with this plugin, as well as manually loading the view with the command :loadview but trying to use an autocmd to load this view fails where other filetypes would not. Here is a basic vimrc with VimPlug where this happens:

call plug#begin('~/.config/nvim/plugged')
" Vue indentation
Plug 'leafOfTree/vim-vue-plugin'
call plug#end()

set foldmethod=syntax

" Remember folds when switching buffers
augroup remember_folds
 autocmd!
 autocmd BufLeave,BufWinLeave ?* mkview | filetype detect
 autocmd BufReadPost ?* loadview | filetype detect
augroup END

and the resulting error:

Error detected while processing /home/tradam/.local/share/nvim/view/~=+Documents=+Web=+form=+src=+App.v
ue=:
line  122:
E490: No fold found
Press ENTER or type command to continue

Note that the first time you open a file it is expected to fail, as you have not saved a view yet, but on any subsequent opening of the buffer it should be able to load the view but vue files with this plugin do not(unless called manually with :loadview after the file is open). I speculate what could be happening is the plugin doesn't initialise until after the autocmd is called so vim doesnt yet understand how to apply the folds. This would explain why the manually calling :loadview works and why the view can be saved with autocmd. I have tried setting up the autocmd with various different "groups" but all of them yielded the same error.

Sadly this means that whenever I switch load buffers all the folds are reset and are closed.

Hi, there.

I speculate what could be happening is the plugin doesn't initialise until

You're right. There was a timer to enable fold, which I removed to support mkview/loadview. a8decb7

and the resulting error:
Error detected while processing ...

I think the error is because the autocmds matches those saved view files. And filetype detect will make vim become slow.

Therefore, I recommend you try the setup below, as shown in the help :h loadview

autocmd BufWinLeave *.* mkview
autocmd BufWinEnter *.* silent loadview

Thank you for the quick reply, and thanks for making and maintaining this awesome plugin!

I have updated the plugin with :PlugUpdate as well as changing the autocmd to the ones you recommended but I still get that same E490: No fold found error.

I have also forgotten to mention in my original issue that I use Neovim so I apologise for that, however I have now tested this with Vim using the file I pasted below and the same E490 error happens. I have also tried deleting the vim-vue-plugin directory and reinstalling to no avail.

Relevant Vimrc tried with Vim
source $VIMRUNTIME/defaults.vim

call plug#begin ('~/.vim/plugged')
" Vue indentation
Plug 'leafOfTree/vim-vue-plugin'
call plug#end()

set foldmethod=syntax

" Remember folds when switching buffers
augroup remember_folds
 autocmd!
 autocmd BufWinLeave *.* mkview
 autocmd BufWinEnter *.* silent loadview
augroup END

I checked both vim & nvim and ends up with autocmd below, which should suppress those error messages. Please note the ? and ! added.

 autocmd BufWinLeave ?* mkview
 autocmd BufWinEnter ?* silent! loadview

I also wonder, are the folds kept across buffers after you updated this plugin? If not, what kind of buffer filenames doesn't it work for?

I'm closing this issue. Feel free to reopen it if any questions.