tags:

views:

312

answers:

4

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?

thanks

A: 

:!chmod

and if vi still doesn't want to write it,

:se cpo-=W

JustJeff
+7  A: 

Just use

:!chmod +w %

in command mode. % will be replaced by the current file name.

Tox'N
+3  A: 

Have you tried

!chmod +w %

The % represents the current filename.

You could also map a key to this like Ctrl-W.

:map <C-w> :!chmod +w %<CR>

Note that you type Ctrl-V Ctrl-M to get the

Michael Dillon
+5  A: 

If you have the rights to write to the file, then you can just use exclamation mark to force it:

:w!

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 %
Michael Krelin - hacker
yes but I dont want to type w! all time... only w
vehomzzz
You don't want to write to file all the time either ;-)
Michael Krelin - hacker