Tell me more ×  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 the vi?  something like that !r
chmod +w filename ?  is there a shortcut to refer to the
currently open file without spelling it 50 letter name?
share|improve this question add comment  4 Answers  up vote 17
down vote accepted  Just use  :!chmod +w %  in command mode. %
will be replaced by the current file name.  share|improve this
answer add comment  If you have the rights to write to the file,
then you can just use exclamation mark to force it:   If you
don't have the rights and need to change user, but still want to
write to the file, sometimes you may go for something like  :w
!sudo tee % share|improve this answer yes but I dont want to
type w! all time... only w –  vehomzzz Oct 22 '09 at 12:00 You
don't want to write to file all the time either ;-) –  Michael
Krelin - hacker Oct 22 '09 at 12:02 add comment  Have you tried
!chmod +w %  The % represents the cu