1

I include set number in my .vimrc file to have line numbers automatically displayed upon opening a file. I also use the following code block to automatically save and load the view when closing and opening buffers, mainly for the purpose of saving folds:

augroup AutoSaveFolds
  autocmd!
  autocmd BufWinLeave * mkview
  autocmd BufWinEnter * silent loadview
augroup END 

However, one view setting that I wish to avoid saving is line numbering. Currently, if I hide line numbering and then close a file, line numbering is unset when that file is reopened. This is true even if set number is placed after the augroup block in my .vimrc file.

Can I circumvent this limitation, such that line numbering will automatically be enabled any time a buffer is opened while still allowing fold settings to be persistent?

2
  • 1
    Does removing localoptions and/or options from the value of the 'viewoptions' option help? Maybe something like set vop-=localoptions vop-=options or set vop=folds,cursor,curdir...
    – user938271
    Commented Sep 28, 2018 at 20:31
  • @user938271: Yes, thanks, I'll accept that as an answer. (I used set vop=folds,cursor,curdir.)
    – user001
    Commented Sep 28, 2018 at 21:30

1 Answer 1

2

From :h :mkview:

The output of ":mkview" contains these items: ...

  1. Restore mappings, abbreviations and options local to the window if 'viewoptions' contains "options" or "localoptions".

The global option 'viewoptions' controls what will be saved/restored when you execute :mkview, :loadview. Its default value contains the item options. So maybe yours contained options as well, and/or localoptions. Here are how these items are described in :h 'vop:

options options and mappings local to a window or buffer (not global values for local options)

localoptions same as "options"

This may be the reason why your 'number' option was saved/restored. To prevent this, you can remove the items from 'vop':

set vop-=options vop-=localoptions

Or reset 'vop' entirely:

set vop=folds,cursor,curdir
        │     │      │
        │     │      └ save the local working directory
        │     └ save the cursor position
        └ save the folds

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.