How do I control what state gets saved when I use :mkview to snapshot a window?
Answer
:set viewoptions=cursor,folds,slash,unix
Explanation
The viewoptions setting is a comma-separated list that determines exactly what :mkview (and the auto-save view pattern) stores in a view file. The default value includes options, which saves all local option overrides — a frequent source of confusing bugs when views go stale.
How it works
:mkviewwrites a script toviewdircapturing the items listed inviewoptions:loadviewre-applies that script to restore the saved state- The
optionsitem (included by default) saves every local option value, includingfoldmethod,filetype, and others set by your filetype plugin - If a view file is stale, it can silently re-apply an old
foldmethod=manual, overriding the one your ftplugin sets
Recommended configuration
For most users, saving only cursor position and folds is sufficient:
set viewoptions=cursor,folds,slash,unix
Or, to surgically remove just the problematic item while keeping defaults:
set viewoptions-=options
Example
A common auto-save pattern:
autocmd BufWinLeave * mkview
autocmd BufWinEnter * silent! loadview
Without set viewoptions-=options, this can silently override foldmethod and other settings your filetype plugin configures on every file open.
Tips
- Inspect current value:
:set viewoptions? - Available items:
cursor,folds,slash,unix,options,localoptions,curdir slashandunixare recommended for cross-platform compatibility with view files