Track changes to readonly

52 views
Skip to first unread message

Aaron Heifetz

unread,
Nov 17, 2023, 5:53:22 AM11/17/23
to vim_use
I wonder how it is possible to react to changes to a buffer's readonly flag both,
- after starting vi, e.g. with gvim -c "set ro" (not gvim -R), and
- when changing the flag via the command line.
So far I haven't found an event covering these cases.
I want to change the background ("highlight Normal") dynamically based on the buffer's state.

Any ideas?

Christian Brabandt

unread,
Nov 17, 2023, 6:53:16 AM11/17/23
to vim...@googlegroups.com

On Do, 16 Nov 2023, 'Aaron Heifetz' via vim_use wrote:

> I wonder how it is possible to react to changes to a buffer's readonly flag
> both,
> - after starting vi, e.g. with gvim -c "set ro" (not gvim -R), and
> - when changing the flag via the command line.

I don't understand the difference between those two checks. For the
first one, you can call a function on VimEnter, check the flag and set
your background color, see also the 'wincolor' setting. But how do you
change the flag via the command line, if not during startup?

You may also trigger a function on an OptionSet autocommand, that reacts
to setting those option values after startup.

Thanks,
Christian
--
Hell is empty and all the devils are here.
-- Wm. Shakespeare, "The Tempest"

Aaron Heifetz

unread,
Nov 18, 2023, 9:29:51 AM11/18/23
to vim_use
@Christan

Thanks! "OptionSet" was the event I had been looking for. I actually failed to recognize it...

Christian Castro

unread,
Nov 20, 2023, 7:37:16 PM11/20/23
to vim...@googlegroups.com
Hello,

How do you change the options in the _vimrc file?
I'm using a newer version of gVim 9.0 and when I launch gVim, there are options under File -> Towards the bottom -> I've tried all of them but the _vimrc file doesn't get modified and when I open gVim again, my options (background color, etc) are gone.

I'd like to set these:
set nohlo
set ts=4
set sw=4

Please let me know if the _vimrc file is editable from gVim or am I going about this the wrong way (and what the right way is).


Thank you

****WARNING**** This email message (including any attachments) are to be treated as confidential/proprietary and may contain copyrighted or other legally protected information. It is intended only for the addressee(s) identified above. If you are not the addressee(s), or an employee or agent of the addressee(s), please note that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this information in error, please destroy the information and notify the sender of the error. Thank you.

Tim Chase

unread,
Nov 20, 2023, 8:03:36 PM11/20/23
to vim...@googlegroups.com
On 2023-11-21 00:37, Christian Castro wrote:
> How do you change the options in the _vimrc file?

It's just a text-file, so you can put in the settings you want.
So you can just put these commands in that file:

set nohlo
set ts=4
set sw=4

> Please let me know if the _vimrc file is editable from gVim or
> am I going about this the wrong way (and what the right way is).

So yes, you should be able to edit it like any other file. It even
comes with a handy built-in variable, so within vim you can

:e $MYVIMRC

and it will open the appropriate file.

Alternatively, you can use the

:mkvimrc

command to take whatever your current settings are and write them
to your vimrc file.

-tim

:help $MYVIMRC
:help :mkvimrc




Tony Mechelynck

unread,
Nov 20, 2023, 8:21:09 PM11/20/23
to vim...@googlegroups.com
IIUC, :mkvimrc can create a vimrc but not modify an existing one.

The vimrc (i.e. the .vimrc or _vimrc) is a plain text file: it is made
to be editable, typically with Vim. I recommend to start with a vimrc
containing

:runtime vimrc_example.vim

and then add below that (or rarely above it) whatever suits your fancy
to add settings not set by the vimrc_example.vim (and the defauts.vim
which it sources) or to override those they do set.

Best regards,
Tony.

Christian Castro

unread,
Nov 22, 2023, 2:53:42 PM11/22/23
to vim...@googlegroups.com
Silly question but when I try to edit the file it comes back that it's not editable.
Weird thing, Windows doesn’t show that it's write protected and there is no Windows service for VIM nor is there a VIM program running as per Task Manager, so I have no idea why Windows is saying it's not editable, unless VIM has done something fancy in the registry somehow.

Any advice on how to unlock the _vimrc file in C:\Program Files (x86)\Vim\ ?


Thanks
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXsYEEzPgLQjeLh%2BtWzZBVd1zLku4x2t0m0KqzG46Ov%2BLA%40mail.gmail.com.

Tim Chase

unread,
Nov 22, 2023, 3:35:23 PM11/22/23
to vim...@googlegroups.com
On 2023-11-22 19:53, Christian Castro wrote:
> Weird thing, Windows doesn???t show that it's write protected
> and there is no Windows service for VIM nor is there a VIM
> program running as per Task Manager, so I have no idea why
> Windows is saying it's not editable, unless VIM has done
> something fancy in the registry somehow.
>
> Any advice on how to unlock the _vimrc file in C:\Program Files (x86)\Vim\ ?

That sounds like a suspect location, as a system-install location.
Usually it should be something like

C:\Users\ccastro\_vimrc

-tim





Reply all
Reply to author
Forward
0 new messages