6

How can I prevent VIM to set modifiable to off?

I have many files opened in VIM and when I want to navigate to a directory I use :E. Sometimes (I cannot reproduce when) VIM sets modifiable to off. When I go back to my file, I cannot make changes until I run :set modifiable.

I want modifiable to be on always. How can I do this?

Seems that this question doesn't solve my problem...

Community
  • 1
  • 1
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • I would suggest don't "automatically set it always on", instead, you could create a shortcut (mapping), e.g. `m` to `:set ma`. in this way, you know which buffer you want to do force modification. it could avoid some dangerous changes in some case. – Kent Sep 13 '13 at 09:17
  • @Kent But... it's so annoying to run always `:set ma` and then `:w!` (because readonly turns on also)... Isn't any safe solution? – Ionică Bizău Sep 13 '13 at 09:23
  • I'm using nerdtree facing the same problem. – laike9m Feb 19 '14 at 07:55
  • @laike9m I use nertree, also - but I don't think that that's the problem. My problem was fixed after [this change in `.vimrc` file](https://github.com/IonicaBizau/configs/commit/9e2aebde73b8e70d39dc20f79df74968e29a02c1). – Ionică Bizău Feb 19 '14 at 08:09
  • So now you can add file using nerdtree without typing `:set ma`? I don't see how you did it in your `.vimrc`. – laike9m Feb 19 '14 at 08:18
  • @laike9m I didn't have problems with nerdtree. I guess it was because of one of the `.vimrc` functions. – Ionică Bizău Feb 19 '14 at 08:27

2 Answers2

10

The problem lies in the sometimes (I cannot reproduce when). Vim doesn't set this on its own, it's probably a plugin or other part of your configuration that runs amiss. Next time this happens, find out where this got set via

:verbose setlocal modifiable?

Once the root cause is known, you can do something about it.

If everything fails, and you also cannot / do not want to (temporarily, for testing) shut down plugins and configuration, the "big hammer" method would be an autocmd like this, which attempts to always turn off the option:

:autocmd BufWinEnter * setlocal modifiable
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Yes.. I have some installed plugins. How can I know which one produces the problem? [This is my .vimrc](https://github.com/IonicaBizau/configs/blob/master/vim-files/.vimrc) – Ionică Bizău Sep 15 '13 at 14:52
  • 1
    @Johnツ The `:verbose` may already tell you if you're lucky. Otherwise, binary search is an alternative: Disable half of your plugins and see whether the problem's gone. – Ingo Karkat Sep 15 '13 at 19:06
  • I don't think binary search is a good solution here. Maybe it is the only one, but considering the problem happens randomly, you'd need to spend days working without half of your plugins. – MaiaVictor Dec 21 '14 at 02:17
1

I found that MacVim would always open new files with modifiable off after upgrading my Mac to Leopard. In my case a newer version of NERDTree fixed it for me. I installed NERDTree with pathogen, so a git pull from ~/.vim/bundle/NERDTree did the trick.

clayg
  • 347
  • 1
  • 3
  • 9
  • 1
    Just in case it helps someone else, I found I could turn off the **non modifiable** notice by changing the line that says `setlocal nonmodifiable ` to `setlocal modifiable ` in `~/.vim/bundle/nerdtree/lib/nerdtree/ui.vim` – Cabbage soup Nov 04 '15 at 10:06