Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent insert mode in vim

Tags:

vim

I often like to have a copy of the file that I am working on open on a second monitor, usually to assist with writing tests. I sometimes mindlessly attempt to edit it on this monitor, rather than the most up to date one. To prevent this, I have been setting read only mode with :set ro but that doesn't prevent me from making changes, it only prevents me from saving.

I would like a lock that turns off the ability to go into insert mode. I could create a toggle that remaps all the insert mode keys, but I was wondering if there is a better solution?

like image 214
asmacdo Avatar asked Feb 12 '26 01:02

asmacdo


2 Answers

Yes, it's possible. :set nomodifiable in the buffer you want to mark read-only. This is used by plugins like taglist to create non-modifiable buffers.

like image 173
Chris Smeele Avatar answered Feb 15 '26 15:02

Chris Smeele


You can open with the argument -M. This prevents edits to the buffer.

like image 34
kaz Avatar answered Feb 15 '26 16:02

kaz