LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 12-11-2020, 06:23 AM   #1
Alok Rai
Member
 
Registered: Aug 2015
Posts: 245

Rep: Reputation: Disabled
help with vi


Am trying to learn vi but seem to have come up with an initial problem.
I have been following a ryanstutorial about learning bash, and I also have a Linux in easy steps, by Mike McGrath at hand.

I am using Linux Mint 19 XFCE.

I am able to insert text. But when I try and save and exit, I run into problems with all the different commands that I can find in my two sources. Thus:

ZZ produces the message E212: Can't open file for writing
[ctrl] x produces the same message
:qa brings up the messages E37: No write since last change
and E212 - ditto - for buffer "test"
:qa! takes me out of vi and back to the shell prompt
:w - which I found in McGrath, is no help either.

This is probably something very elementary. But, at my level of skill, insurmountable.
 
Old 12-11-2020, 06:50 AM   #2
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,587
Blog Entries: 19

Rep: Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455
I always exit with wq. w writes out the text and q quits. q by itself doesn't work if the file is dirty; you get that warning about not having written since the last change. q! overrides that, but it means your changes aren't saved. Save that one for when you have made a mess of the file and you want to just cancel the edit altogether. To save your work use w for a file that already has a name or w filename for one that doesn't.
 
1 members found this post helpful.
Old 12-11-2020, 06:54 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
ESC wq
or
ESC wq!

Both of those are intended to write and quit, you can omit the 'q' to not quit the editor.

If it complains that it can't open the file for writing, check the permissions for the file and the user from which you are editing the file.
 
Old 12-11-2020, 08:29 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by Alok Rai View Post
ZZ produces the message E212: Can't open file for writing
My guess: You are trying to create a file in a location that is not writable for you. Or the file itself is not writable. How did you invoke vi?

Quote:
:qa brings up the messages E37: No write since last change
The q command quits without saving. It only does it if the document is unchanged, or when you shout at it by adding an exclamation mark q!
Quote:
:qa! takes me out of vi and back to the shell prompt
And here is the exclamation mark.
Quote:
:w - which I found in McGrath, is no help either.
Same as ZZ.
 
Old 12-11-2020, 08:33 AM   #5
Alok Rai
Member
 
Registered: Aug 2015
Posts: 245

Original Poster
Rep: Reputation: Disabled
Thanks. I was doing the w and the wq - with Esc and the colon : - but the user-permission was the key. Tried it with sudo, and it worked. Now, is there a way in which I can open vi without needing to do the sudo thing each time?
 
Old 12-11-2020, 08:41 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Yes, don't open files in directories you do not have the permissions for.

As a side not, I use :x, which dies the same as :wq
 
1 members found this post helpful.
Old 12-11-2020, 08:50 AM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by Alok Rai View Post
Thanks. I was doing the w and the wq - with Esc and the colon : - but the user-permission was the key. Tried it with sudo, and it worked. Now, is there a way in which I can open vi without needing to do the sudo thing each time?
I don't recommend you try to supersede this. Yes, technically you can login as root, but there's a reason why the file permissions sometimes are even set to read-only for ALL users, including root, because you need to think about editing that file. You should make a copy of any files you intend to edit, if they are configuration type of files or profile files. If you edit it and find that things do not work, you can then use the former copy of return the file to it's original working form. Nothing wrong with keeping incremental backups, such as you are learning, editing, you make one change, it works. So then you try to make other changes, over time suddenly nothing is working, but you may find that reversing the one last change isn't sufficient, likely because you didn't re-check the ability to work at each juncture. This is very common when experimenting. Nothing wrong with it, but as far as uniformly allowing yourself to always be able to edit files that are protected? That's dangerous, even for those with great experience, we all make errors. If you're editing files owned by your username, within your user home directory, then there should be no protection issues at all, unless you've tinkered with your default umask or something.
 
Old 12-11-2020, 09:49 AM   #8
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,587
Blog Entries: 19

Rep: Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455
The whole point of the Linux permissions system is that it allows you to explore your system safely because you are not root and therefore cannot do any harm. It also prevents malware that you might download from the internet in your name from doing any harm to your system. Becoming root just so you can ignore permissions is reckless, and so is changing permissions to save a few keystrokes. Distro developers take great pains to ensure that system files and directories have correct permissions to ensure trouble-free working. I've been using Linux for more than fifteen years now and I leave permissions well alone because I know they are there for my protection.
 
1 members found this post helpful.
Old 12-11-2020, 12:36 PM   #9
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,498

Rep: Reputation: Disabled
Quote:
I am able to insert text. But when I try and save and exit, I run into problems.....
You are trying to edit a system file as an ordinary user, & as you are learning, you are being protected from wrecking/crashing your system.

Practice on a file that you own.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
help :(install sudo apt-get install synaptic problem help me dear :( help me help me zeeshanayub Linux - Newbie 3 10-21-2014 07:02 PM
Help, help help help help drknownothing Linux - Networking 2 10-24-2004 03:05 AM
help, help, help, help, help....cmi8738 will not work... AMArt79196 Red Hat 2 07-05-2004 06:13 PM
Help Help Help, eh.. Help. Pwcca Slackware 7 02-26-2003 11:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11: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
Open Source Consulting | Domain Registration