How can I edit the default vimrc file? (it's read only, and chown and chmod says 'operation not permitted') How can I edit the default vimrc file on osx? (sudo chown ... gives Operation not permitted )

In osx vim /usr/share/vim/vimrc is the default vimrc file

My username is 'apple'

If I try to do vim /usr/share/vim/vimrc then it says 'read only'

~/.vim$ ls -l /usr/share/vim/vimrc
-rw-r--r--  1 root  wheel  532  5 Apr  2017 /usr/share/vim/vimrc
~/.vim$ 

If I try to change ownership of the file 

~/.vim$ sudo chown apple /usr/share/vim/vimrc 
chown: /usr/share/vim/vimrc: Operation not permitted
~/.vim$ 


similarly with permissions (giving write access to non-root users temporarily for the purposes of me editing the file)

~/.vim$ sudo chmod 666 /usr/share/vim/vimrc
chmod: Unable to change file mode on /usr/share/vim/vimrc: Operation not permitted
~/.vim$ 


sudo chown does work on another file though, so it's not a password issue.

~/.vim$ cp /usr/share/vim/vimrc zzz
~/.vim$ ls -l zzz
-rw-r--r--  1 apple  staff  532  3 May 23:10 zzz
~/.vim$ sudo chown root zzz
~/.vim$ sudo chown apple zzz
~/.vim$
This would be a System Integrity Protection (SIP) issue. See About System Integrity Protection on your Mac. Error message shown below is often displayed when SIP prevents a command from executing.

Operation not permitted


Basically, you need to either temporarily disable SIP or edit the file while booted to macOS Recovery.