Sparks135
Posts: 104
Joined: Tue Feb 28, 2017 7:44 pm

I had to add two lines to a file but can't save.

Sat Mar 25, 2017 2:53 pm

I installed an auto shutdown board, and had to add two lines to "sudo vim.tiny /etc/rc.local" I was able to edit the file but can't figure out how to save my edit. I tried Ctrl>W to save and exit it did nothing I opened the file in Terminal. I tried Ctrl>O no luck either. Any help would be greatly appreciated. The lines I added were
gpio mode 25 out
gpio write 25 1

jahboater
Posts: 4677
Joined: Wed Feb 04, 2015 6:38 pm

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 3:06 pm

In vi I use ":wq"
':' to enter command mode
'w' to write the file
'q' to exit vi.

Sparks135
Posts: 104
Joined: Tue Feb 28, 2017 7:44 pm

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 3:12 pm

jahboater wrote:In vi I use ":wq"
':' to enter command mode
'w' to write the file
'q' to exit vi.
Please more info as I am a novice and not sure of the procedure. I opened the file using sudo, and entered the lines, but whatever I try to save nothing.

jahboater
Posts: 4677
Joined: Wed Feb 04, 2015 6:38 pm

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 3:16 pm

Sparks135 wrote:
jahboater wrote:In vi I use ":wq"
':' to enter command mode
'w' to write the file
'q' to exit vi.
Please more info as I am a novice and not sure of the procedure. I opened the file using sudo, and entered the lines, but whatever I try to save nothing.
Did you try typing :wq ? The letters : then w then q one after the other followed by the <return> key.
If thats difficult, then try the nano editor which works with control keys that I suspect you are used to. It also has a helpful menu at the bottom of the screen.
vi (vim) is very powerful and fast and perhaps not so easy to learn.
Last edited by jahboater on Sat Mar 25, 2017 3:20 pm, edited 1 time in total.

Sparks135
Posts: 104
Joined: Tue Feb 28, 2017 7:44 pm

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 3:20 pm

jahboater wrote:
Sparks135 wrote:
jahboater wrote:In vi I use ":wq"
':' to enter command mode
'w' to write the file
'q' to exit vi.
Please more info as I am a novice and not sure of the procedure. I opened the file using sudo, and entered the lines, but whatever I try to save nothing.
Did you try typing :wq ? The letters : then w then q one after the other. If thats difficult, then try the nano editor which works with control keys that I suspect you are used to. It also has a helpful menu at the bottom of the screen.
vi (vim) is very powerful and fast and perhaps not so easy to learn.
Tried :wq all it did was type that on the screen. How do I open the file in the Nano editor?

jahboater
Posts: 4677
Joined: Wed Feb 04, 2015 6:38 pm

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 3:22 pm

Sparks135 wrote: Tried :wq all it did was type that on the screen. How do I open the file in the Nano editor?
Sorry, you have to press the "return" key after the q. Its just a normal command line.

blaablaaguy
Posts: 623
Joined: Sun Sep 27, 2015 3:26 pm

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 3:26 pm

Sparks135 wrote:
jahboater wrote:
Sparks135 wrote: Please more info as I am a novice and not sure of the procedure. I opened the file using sudo, and entered the lines, but whatever I try to save nothing.
Did you try typing :wq ? The letters : then w then q one after the other. If thats difficult, then try the nano editor which works with control keys that I suspect you are used to. It also has a helpful menu at the bottom of the screen.
vi (vim) is very powerful and fast and perhaps not so easy to learn.
Tried :wq all it did was type that on the screen. How do I open the file in the Nano editor?
To use nano just type "nano" (without quotes) and then the file name.
This signature intentionally left blank.

klricks
Posts: 6587
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 3:29 pm

Sparks135 wrote:
jahboater wrote:In vi I use ":wq"
':' to enter command mode
'w' to write the file
'q' to exit vi.
Please more info as I am a novice and not sure of the procedure. I opened the file using sudo, and entered the lines, but whatever I try to save nothing.
I would suggest to use nano editor instead.

Code: Select all

sudo nano /etc/rc.local
After edits use CTRL-x then Y to confirm save
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 3:33 pm

Sparks135 wrote:Tried :wq all it did was type that on the screen.
That's because he forgot to tell you to hit the escape key first. In vi, you hit the escape key constantly. The only thing it doesn't do is let you escape. You start nano by typing nano.

Sparks135
Posts: 104
Joined: Tue Feb 28, 2017 7:44 pm

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 4:07 pm

So the ESC key is the missing link.

jahboater
Posts: 4677
Joined: Wed Feb 04, 2015 6:38 pm

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 4:19 pm

Sparks135 wrote:So the ESC key is the missing link.
Yes, sorry, I had assumed you had done that. Vim is called bi-modal in that you are either in "insert" mode or "command" mode. ESC gets you out of insert mode.

Its very clever, you could for example type i xxxxx esc to insert a few letter x's. Then typing . does the entire insert again, and 5 . does that insert five times. "5 d w" deletes the next five words and so on.

With practice you can do much more work with fewer key presses in vi than you can in other, simpler, editors. You just have to think more!

Its even more confusing because : gets you into a command line mode like the old "ex" or "ed" editors where you can do even more complex, global, edits.

As I and others said though, nano is easier get started with.

User avatar
Ferdinand
Posts: 236
Joined: Sun Dec 01, 2013 2:24 pm
Location: Leiderdorp, NL

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 4:35 pm

Hi Sparks135,

Here is a links to a vi manual https://www.cs.colostate.edu/helpdocs/vi.html
Success with your project!
Ferdinand

jahboater
Posts: 4677
Joined: Wed Feb 04, 2015 6:38 pm

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 4:40 pm

Vi is short for "visual" and vim is short for "vi improved", a later version. vi has been around since the 70's.

User avatar
DougieLawson
Posts: 36105
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 4:55 pm

jahboater wrote:Vi is short for "visual" and vim is short for "vi improved", a later version. vi has been around since the 70's.
In just the same way that nano is a clone of the ancient pico editor (which I dislike intensely). Vi is a bit quirky. You need to learn the basics [esc][:][w][q] and [esc][:][q][!]. Vim also comes with an extensive help system.

At least nobody suggested emacs.

If you can get a terminal window open, there's always leafpad and sudo leafpad which gives you a GUI editor (running sudo leafpad runs it with root privileges, so you can edit/update/destroy any file with it).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

jahboater
Posts: 4677
Joined: Wed Feb 04, 2015 6:38 pm

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 5:46 pm

DougieLawson wrote: At least nobody suggested emacs.
Aha, now you mention it ....
I just tried it on a Pi3 and while it took ages to install, it actually runs really well.
The grand daddy of editors, more of an IDE or way-of-life than a text editor. It does anything and everything and is very easy to extend or customize if you are happy programming in Lisp! Emacs is short for "editor macros"

Martin Frezman
Posts: 1020
Joined: Mon Oct 31, 2016 10:05 am

Re: I had to add two lines to a file but can't save.

Sat Mar 25, 2017 6:01 pm

The best way to save-and-exit in vi (all versions) is ZZ.

I learned that long before I learned :wq (and things like that).
If this post appears in the wrong forums category, my apologies.

Return to “Beginners”