I am traversing through a C code in Vim using cscope. Sometimes while traversing, some key gets pressed or mouse gets right-clicked and the Vim enters in insert mode, and it creates a mess to undo the changes and all. I just want to read the code, and hence want to open Vim in read-only mode. Is it possible? How can it be done so?
You can try to reuse
modifiable setting (
set noma (nomodifiable) for a current buffer -- it will prevent any modifications you will try to do for that buffer.
Not sure how to connect it with cscope -- I have never used it and I don't know what is your workflow...
Just an idea -- to use autocommand
autocmd! BufEnter * :set noma
this will turn on no modifiable setting for all your buffers.
To revert do the same with
autocmd! BufEnter * :set ma
You can limit it to
autocmd! BufEnter *.c,*.h :set noma
Create mappings (add to your .vimrc):
nnoremap <f5> :set noma<CR>:autocmd! BufEnter *.cpp,*.c,*.h :set noma<CR> nnoremap <f6> :set ma<CR>:autocmd! BufEnter *.cpp,*.c,*.h :set ma<CR>
<f5>when you want to do your cscope.
Then again, to be more safe you have to check if it was you who set nomodifiable flag before removing it.
Probably it would be better to use
:bufdo to remove nomodifiable flag instead of autocommand. (Plus don't forget to turnoff autocommand from