vimtricks.wiki Concise Vim tricks, one at a time.

How do I stop :mkview from restoring local options when loading a view?

Answer

:set viewoptions-=options

Explanation

When you use :mkview and :loadview, Vim stores more than folds and cursor position. By default, it can also persist local window and buffer options, which may unexpectedly reapply settings like cursorline, number, or local fold configuration in files where you do not want them. Removing options from viewoptions keeps view files focused on layout/state instead of local option side effects.

How it works

  • :set viewoptions-=options removes the options flag from the viewoptions option list
  • After this change, :mkview no longer writes local options into the saved view
  • :loadview still restores practical view state (cursor position, folds, etc.) without reapplying those local option values

This is especially useful when you work across mixed filetypes and rely on filetype plugins or project-local config to set options dynamically.

Example

Before changing viewoptions, loading a view may unexpectedly restore local UI settings:

Open file -> :setlocal cursorline -> :mkview
Later -> :setlocal nocursorline -> :loadview
Result: cursorline turns back on from the view

After removing options:

:set viewoptions-=options
:mkview

Now :loadview restores navigation state but does not force prior local option values back in.

Tips

  • Inspect current behavior with :set viewoptions?
  • Add this to your vimrc/init.vim if you want it consistently
  • Use :help 'viewoptions' to tune exactly what gets stored

Next

How do I append the same suffix to every selected line in Visual mode?