I sometimes open a read-only file in vi, forgetting to do chmod +w before opening it. Is there way to change the file from within vi?
chmod +w
Something like !
!
Have you tried
!chmod +w %
The % represents the current filename.
You could also map a key to this like Ctrl-W.
:map :!chmod +w %
Note that you type Ctrl-V Ctrl-M to get the