LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-13-2002, 02:12 PM   #1
Rubicone
Member
 
Registered: Oct 2001
Posts: 36

Rep: Reputation: 15
Using VI


After launching vi, writing some text and attempting to save it I get the error message "Can't open file for writing." Since I did not open a file to begin with don't know what this is in reference to. Does one have to specify the filename before trying to save it? That is issue the command vi <filename> first? The method that I tried to save the file is as follows:
1:Go into command mode using the Esc key
2:Then issue the :w command followed by the filename and pressing the Enter key.
3: What follows is the noted error message or the option of continuing with the command. This implies that the command is incomplete. Pressing the Tab/Ctrl keys for some hints does not help and I could not see any infomation in the Man pages on this. TIA for suggestions on resolving this issue.
 
Old 03-13-2002, 02:25 PM   #2
hanzerik
Member
 
Registered: Jan 2002
Location: Cheyenne Wyoming
Distribution: Debian/Raspbian/Mint
Posts: 717

Rep: Reputation: 32
Make sure the directory you are in is writable by you.
 
Old 03-13-2002, 02:42 PM   #3
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 235Reputation: 235Reputation: 235
you can also name the file wherever after your :wq! command.. ex:

:wq! /etc/somefile.txt etc etc...

-trickykid
 
Old 03-13-2002, 03:05 PM   #4
Rubicone
Member
 
Registered: Oct 2001
Posts: 36

Original Poster
Rep: Reputation: 15
After I issue the :w command do I have to specify the absolute path to where the file should be saved also?Or, if I am in my Home directory will not vi save it to there by default?
 
Old 03-13-2002, 03:19 PM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 235Reputation: 235Reputation: 235
if your in your home directory, it will save there by default.. but be sure not to just issue :w , you need to add the q! also so it quits as well.. well if your done with the file.

-trickykid
 
Old 03-13-2002, 06:48 PM   #6
TacKat
Member
 
Registered: Jan 2002
Distribution: LFS
Posts: 90

Rep: Reputation: 15
If you do a ":wq" you don't really need a "!" on the end. ":q!" just forces a quit even if you haven't saved, which you just did.
 
Old 03-13-2002, 07:08 PM   #7
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally posted by TacKat
If you do a ":wq" you don't really need a "!" on the end. ":q!" just forces a quit even if you haven't saved, which you just did.
true.. personal habit of mine i guess..
 
Old 03-13-2002, 07:24 PM   #8
hanzerik
Member
 
Registered: Jan 2002
Location: Cheyenne Wyoming
Distribution: Debian/Raspbian/Mint
Posts: 717

Rep: Reputation: 32
yea it has become a habit just to do a :wq!
 
Old 03-13-2002, 09:50 PM   #9
Rubicone
Member
 
Registered: Oct 2001
Posts: 36

Original Poster
Rep: Reputation: 15
I tried the :wq command followed by the filename and still get the same error message. When I try to specify a path after the filename I get the message that only one name is allowed per file. Don't know what, if anything, I may be doing wrong unless someone has overlooked something. I wonder whether or not the filename should precede the :wq command?

Last edited by Rubicone; 03-13-2002 at 09:52 PM.
 
Old 03-14-2002, 02:28 AM   #10
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 68
When you first open vi you should state the name of the file you would like to save it as. For example: #vi howtousevi# would be opening a new file and naming it "howtousevi". Then at the end when you try to save with :wq it will simply right over the empty file named "howtousevi". I don't know if this will help or not, but good luck.

I found this information at: Linux.org
 
Old 03-14-2002, 03:21 AM   #11
gui10
Member
 
Registered: Mar 2001
Distribution: enigma, slack8
Posts: 677

Rep: Reputation: 30
well... personal preference here. if i use vi, i usually decide the filename i want first. saves a lot of trouble.



the other solution is: use nano
 
Old 03-14-2002, 07:02 AM   #12
Passive
Member
 
Registered: Mar 2002
Posts: 51

Rep: Reputation: 15
Arrow

It seems that it says "can't open file for writing" when you don't have write access to the place it's trying to write it to.
However, if you simply type
:w /home/username/filename" it should work.
What version of VI are you using?
 
Old 03-14-2002, 08:11 AM   #13
Rubicone
Member
 
Registered: Oct 2001
Posts: 36

Original Poster
Rep: Reputation: 15
Hey Passive your suggestion worked! Thanks for the help. By the way the version of vi that I am using is whatever came with RedHat's 7.2 distribution.

Last edited by Rubicone; 03-14-2002 at 08:12 AM.
 
Old 03-14-2002, 07:25 PM   #14
gui10
Member
 
Registered: Mar 2001
Distribution: enigma, slack8
Posts: 677

Rep: Reputation: 30
at the command line:
vi --version
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off




All times are GMT -5. The time now is 02:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration