When i used following code to keep my folder view, it seemed that
viewdon't work at all (Only [readonly] was shown but it didn't work at all). Is there any misunderstanding about it?
" save and restore view automatically autocmd BufWinLeave * silent! mkview autocmd BufWinEnter * silent! loadview
Thank you for all the people who can help me.
:mkview saves the state of the
'readonly' option. This means if
you previously closed the file when it wasn't read only, then when you reopen it,
:set noreadonly and changes it back. From
The output of ":mkview" contains these items: ... 3. Restore mappings, abbreviations and options local to the window if 'viewoptions' contains "options" or "localoptions". For the options it restores only values that are local to the current buffer and values local to the window.
So changing the value of
'viewoptions' will fix this:
but this will also prevent
:mkview from saving almost every other option.
You can see what happens when you run
:loadview with different values of
'viewoptions' by looking at the file that it generates - the files are in
~/.local/share/nvim/view on neovim, and it's just a bunch of
If you actually want to just restore the cursor position every time then there's
a much simpler method that doesn't involve writing any files, look at
:h restore-cursor. The example there registers its autocmd on BufReadPost, you
can easily change that to