saving a script in vi: vi edit session started with no filename

Asked by matt

I am writing a script for a class in the vi editor, but I did not name it before starting vi. I cannot save the script because there is an error that says E32: No file name. How can I name the file and save it without losing my work? I need specific instructions as I a m anew ubuntu user.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu vim Edit question
Assignee:
No assignee Edit question
Solved by:
marcobra (Marco Braida)
Solved:
Last query:
Last reply:
Revision history for this message
Best marcobra (Marco Braida) (marcobra) said :
#1

In vi please press

esc
:

then type
w yuordesiredfilename

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#2

:w ~/myscript

will save it to your home folder. I suggest you run:

vi myscript; chmod +x myscript

in future, so that a filename is specified.

Then the file 'myscript' will be made. If you want to use an easier editor you can use nano. Obviously if the script is outside $HOME then prefix with sudo. Eg:

sudo nano /usr/bin/myscript; sudo chmod +x /usr/bin/myscript

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#3
Revision history for this message
matt (wgas1911) said :
#4

Thanks marcobra (Marco Braida), that solved my question.