Suppose I had tabstop set to 4 in ~/.vimrc. When I edit a file, I set the tabstop to 5 with :set tabstop=5. After that, I close vim and restarted the terminal. When I open the file again, the tabstop for that file is still set to 5. How to make vim forget all settings (not just tabstop) I made (which I forgot) in that specific file?

Currently, when I open a previously opened file, it restores everything (settings, cursor position, etc) the way they were when I last left it. I'm not sure what causes this though. Here's my .vimrc, I guess it has something to do with BufWinLeave and BufWinEnter there.

What I have tried:

  • reset all settings with :set all& and reload vimrc with :source $MYVIMRC. Somehow the syntax highlighting is off afterward.
  • Create a duplicate file, delete the original one, rename the duplicate file to the original one. No effect.
  • Is it perhaps line 51 (autocmd Filetype dart,html,javascript setlocal tabstop=2 expandtab) that's always setting tabstop to 2 on files of.type Dart, HTML and JavaScript?
    – filbranden
    Commented Apr 15, 2020 at 12:39
  • No, it's not about the tabstop. Thanks anyway, I updated the question to prevent confusion. Commented Apr 15, 2020 at 12:49
  • Yeah, this could be related to the saving and restoring views... Looks like by default views will save options and it will get attached to the file name (so the copy/rename logic won't fix it.) The file saved by :mkview is a Vimscript file, so technically you could even inspect or edit the file to remove commands you don't want/like and then reopen the file again...
    – filbranden
    Commented Apr 15, 2020 at 12:55
  • But then... If you don't want these settings preserved, maybe you shouldn't be saving views anyways? Or if you only want other properties of views preserved, consider removing options from viewoptions, with set viewoptions-=options in your vimrc.
    – filbranden
    Commented Apr 15, 2020 at 12:57
  • (BTW, I can't see a reason to use both Vundle and vim-plug. I'd recommend just migrating the one plug-in you're currently managing with Vundle to vim-plug and dropping Vundle.)
    – filbranden
    Commented Apr 15, 2020 at 13:02

1 Answer 1


The lines that restore your settings are

autocmd BufWinLeave . mkview
autocmd BufWinEnter . silent loadview

They respectively save and load your settings for any file you open.

From the doc (:h mkview)

:mkvie[w][!] [file]
Write a Vim script that restores the contents of the current window.
When [!] is included an existing file is overwritten. When [file] is omitted or is a number from 1 to 9, a name is generated and 'viewdir' prepended. When the last path part of 'viewdir' does not exist, this directory is created. E.g., when 'viewdir' is "$VIM/vimfiles/view" then "view" is created in "$VIM/vimfiles".
An existing file is always overwritten then. Use |:loadview| to load this view again. When [file] is the name of a file ('viewdir' is not used), a command to edit the file is added to the generated file.

And (:h loadview)

:lo[adview] [nr]
Load the view for the current file. When [nr] is omitted, the view stored with ":mkview" is loaded. When [nr] is specified, the view stored with ":mkview [nr]" is loaded.
The combination of ":mkview" and ":loadview" can be used to store up to ten different views of a file. These are remembered in the directory specifiedwith the 'viewdir' option. The views are stored using the file name. If a file is renamed or accessed through a (symbolic) link the view will not be found.
You might want to clean up your 'viewdir' directory now and then.

To forget those settings, you'll have to delete the view file associated to your file. All view files should be located in ~/.vim/view by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.