itchyny/lightline.vim

lightline.vim cause automatically loadview invalid

pilgrimlyieu opened this issue · 19 comments

I use augroup auto_view to memorize the last fold status and cursor position.

augroup auto_view
    autocmd!
    autocmd BufWinLeave *.*    mkview
    autocmd BufWinEnter *.*    silent loadview
    autocmd BufWinLeave _vimrc mkview
    autocmd BufWinEnter _vimrc silent loadview
augroup end

However, if I enable lightline.vim, it will not restore the last cursor position(fold status is normally restored). Instead, it will focus on the first line.

Here is the minimal vimrc I've tested in Vim 9.0.0073.(I use vim-plug as my vim plugin manager)

call plug#begin("~/vimfiles/plugged")
Plug 'itchyny/lightline.vim'
call plug#end()

augroup auto_view
    autocmd!
    autocmd BufWinLeave *.*    mkview
    autocmd BufWinEnter *.*    silent loadview
    autocmd BufWinLeave _vimrc mkview
    autocmd BufWinEnter _vimrc silent loadview
augroup end

Besides, if I disable lightline.vim but keep sub-plugin of lightline.vim, auto_view doesn't work either.

Additionally, if I use :loadview command manually, it can work.

If I disable lightline.vim, it works normally. Since lightline.vim is a wonderful plugin, I wonder that if there is a way to fix it.

By the way, really appreciating your pretty work.

I tested the minimal vimrc but it looks working as intended. What is sub-plugin?

What is sub-plugin?

sub-plugin is something like mengelbrecht/lightline-bufferline. But it is irrelevant.

I've recorded a GIF.

The process is

  1. Open a test file(in GIF is test.vim)
  2. Move to a position
  3. Quit
  4. Reload(The reuslt is that the cursor focus on the first line)
  5. Disable lightline.vim
  6. Redo(The result is restoring cursor position correctly)

2

I don't still have clue yet but this could be a nested event problem. How about adding ++nested flag?

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

I don't still have clue yet but this could be a nested event problem. How about adding ++nested flag?

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

Doesn't work either. 😢

Removing silent shows any errors?

Removing silent shows any errors?

Nothing. And if I use echo to check, it can print message normally.

augroup auto_view
    autocmd!
    autocmd BufWinLeave *.*    ++nested echo 'success' | sleep 1 | mkview
    autocmd BufWinEnter *.*    ++nested echo 'success' | sleep 1 | loadview
    autocmd BufWinLeave _vimrc ++nested echo 'success' | sleep 1 | mkview
    autocmd BufWinEnter _vimrc ++nested echo 'success' | sleep 1 | loadview
augroup end

Can you reproduce this issue?

I cannot reproduce the issue.

set runtimepath+=/tmp/lightline.vim
set laststatus=2

autocmd BufWinLeave * mkview
autocmd BufWinEnter * loadview

Maybe it is the bug of the plugin manager vim-plug?

I change the minimal vimrc to this and it works now.

set runtimepath+=~/vimfiles/plugged/lightline.vim/autoload/lightline.vim
set laststatus=2

autocmd BufWinLeave * mkview
autocmd BufWinEnter * loadview

To my vimrc, I add set runtimepath+=~/vimfiles/plugged/lightline.vim/autoload/lightline.vim and disable lightline.vim and its sub-plugin under the control of vim-plug.

If I don't disable lightline.vim or any sub-plugin, it will not work.

However, I could not use some special settings any more.

Snipaste_2022-07-26_19-22-53

let s:palette = g:lightline#colorscheme#gruvbox#palette
let s:palette.tabline.ale = [['#282C34', '#92A4A4', 0, 21]]

I've install Vim 8.2.4005 to check, and it can work fine. So it is the issue of Vim?

Add the plugin directory, not the autoload file.

set runtimepath+=~/vimfiles/plugged/lightline.vim

Add the plugin directory, not the autoload file.

set runtimepath+=~/vimfiles/plugged/lightline.vim

This take no effect while set runtimepath+=~/vimfiles/plugged/lightline.vim/autoload/lightline.vim can.

Please find the exact version Vim which causes the regression.

Please find the exact version Vim which causes the regression.

Through test, I found that Vim 9.0.0057 is the last version that works. And Vim 9.0.0063 is the first version that cause this issue.

So the issue lies in one or some of them.

9.0.0063: too many type casts for dict_get functions
9.0.0062: compiler warnings for signed/unsigned char
9.0.0061: ml_get error with nested autocommand
9.0.0060: accessing uninitialized memory when completing long line
9.0.0059: test file has wrong name
9.0.0058: Win32: cannot test low level events

Thank you. I was using a bit older version, but now I can reproduce the issue and git-bisected successfully. Here's the minimum configuration with no dependency on plugin. The bad commit is apparently 9.0.0061.

autocmd BufWinLeave * mkview
autocmd BufWinEnter * loadview
autocmd SessionLoadPost * echo

Oh, the problem was already reported to vim/vim#10780.

The issue was resolved by 9.0.0094.

The issue was resolved by 9.0.0094.

I'll install and test after the compiled version released.

Thanks for your effort and patience!

It Works, Thanks again!