How do I save files edited with vim?












64















I can't save changes after editing



sudo vi /etc/network/interfaces


Text before editing:



auto lo
iface lo inet ...


Edited to:



auto eth0
iface eth0 inet dhcp


What key combination or sequence must I press to save this?










share|improve this question




















  • 6





    If you are not comfortable with editing files in terminal based editors like vi or vim, I would recommend using graphical based editor like gedit to open them. Replace sudo vi with gksu gedit.

    – Aditya
    Feb 8 '13 at 15:15








  • 5





    Or use sudo nano Its also command line but a lot more intuitive than vi.

    – Warren Hill
    Oct 19 '13 at 9:46
















64















I can't save changes after editing



sudo vi /etc/network/interfaces


Text before editing:



auto lo
iface lo inet ...


Edited to:



auto eth0
iface eth0 inet dhcp


What key combination or sequence must I press to save this?










share|improve this question




















  • 6





    If you are not comfortable with editing files in terminal based editors like vi or vim, I would recommend using graphical based editor like gedit to open them. Replace sudo vi with gksu gedit.

    – Aditya
    Feb 8 '13 at 15:15








  • 5





    Or use sudo nano Its also command line but a lot more intuitive than vi.

    – Warren Hill
    Oct 19 '13 at 9:46














64












64








64


20






I can't save changes after editing



sudo vi /etc/network/interfaces


Text before editing:



auto lo
iface lo inet ...


Edited to:



auto eth0
iface eth0 inet dhcp


What key combination or sequence must I press to save this?










share|improve this question
















I can't save changes after editing



sudo vi /etc/network/interfaces


Text before editing:



auto lo
iface lo inet ...


Edited to:



auto eth0
iface eth0 inet dhcp


What key combination or sequence must I press to save this?







vim






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 19 '15 at 21:39









Braiam

52k20136222




52k20136222










asked Feb 8 '13 at 14:45









AndAnd

4361510




4361510








  • 6





    If you are not comfortable with editing files in terminal based editors like vi or vim, I would recommend using graphical based editor like gedit to open them. Replace sudo vi with gksu gedit.

    – Aditya
    Feb 8 '13 at 15:15








  • 5





    Or use sudo nano Its also command line but a lot more intuitive than vi.

    – Warren Hill
    Oct 19 '13 at 9:46














  • 6





    If you are not comfortable with editing files in terminal based editors like vi or vim, I would recommend using graphical based editor like gedit to open them. Replace sudo vi with gksu gedit.

    – Aditya
    Feb 8 '13 at 15:15








  • 5





    Or use sudo nano Its also command line but a lot more intuitive than vi.

    – Warren Hill
    Oct 19 '13 at 9:46








6




6





If you are not comfortable with editing files in terminal based editors like vi or vim, I would recommend using graphical based editor like gedit to open them. Replace sudo vi with gksu gedit.

– Aditya
Feb 8 '13 at 15:15







If you are not comfortable with editing files in terminal based editors like vi or vim, I would recommend using graphical based editor like gedit to open them. Replace sudo vi with gksu gedit.

– Aditya
Feb 8 '13 at 15:15






5




5





Or use sudo nano Its also command line but a lot more intuitive than vi.

– Warren Hill
Oct 19 '13 at 9:46





Or use sudo nano Its also command line but a lot more intuitive than vi.

– Warren Hill
Oct 19 '13 at 9:46










4 Answers
4






active

oldest

votes


















117














You're probably in editing/insert mode. You need to type the following sequence :





  1. Esc, to quit edit mode and fallback to command mode ;


  2. :+w+q, start with a : (colon) then press w and finally q to write and quit (or just :w to write without quitting)

  3. then press Enter to valid.






share|improve this answer

































    17














    I usually press ESC and then hold Shift and press z twice. Just like you would like to type two capital Z letters in word editor :) That saves your document and closes your editor.






    share|improve this answer





















    • 3





      Oh man, shift and double z, what was the design logic behind that I wonder, "what's the least intuitive command we can create?", ubuntu sometimes pisses me off like mad

      – S..
      May 25 '14 at 11:10






    • 4





      @Sam, I just wanted to nitpick that vi has nothing in particular to do with ubuntu. Ubuntu was first released on 2004, while vi was created by Bill Joy around 1976, inspired by ed (dating back to 1971). This means that the shortcuts in vi predate those in almost any other still commonly used utility today. In a sort of coincidence, the first version of emacs, which has completely different weird shortcuts, was also released on 1976. Standardization efforts came much much later.

      – yoniLavi
      Nov 21 '14 at 2:00











    • Wow thanks for the info @yoniLavi , my points is still the same though, so hopefully standardization efforts keep advancing.. :)

      – S..
      Nov 21 '14 at 9:12











    • @Sam, vi keybindings are actually a lot more standard than you think; they're virtually ubiquitous. Practically any program can be made to emulate vi keybindings. Even the default Gmail keybindings are obviously (to a Vim user) based off of vi keybindings.

      – Wildcard
      Dec 21 '16 at 0:27











    • what about esc key does not work? Insert mode, just stopped.

      – creator
      Mar 10 '18 at 7:07



















    3














    Check whether you have administrative (root) privileges to edit the file. use this command



    whoami


    If the result is not "root", then you are not supposed to edit the file.



    To login as root user, use the below command



    sudo su


    or



    su


    Edit the file,



    vi /etc/network/interfeces


    After the changes, save the file using




    1. Press Esc to change the mode


    2. :x to save and quit the file


    Thats all






    share|improve this answer

































      0














      this question was answered a long time ago, but in case it comes up in search engines again, this link is a nice vim cheatsheet that you might want to bookmark if you use vim a lot.



      By the way, You can use :wq to save and exit the file ( you should first press esc key to exit insert or replace mode and then press commands ) and use :q! to exit without saving.






      share|improve this answer

























        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "89"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f252760%2fhow-do-i-save-files-edited-with-vim%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        117














        You're probably in editing/insert mode. You need to type the following sequence :





        1. Esc, to quit edit mode and fallback to command mode ;


        2. :+w+q, start with a : (colon) then press w and finally q to write and quit (or just :w to write without quitting)

        3. then press Enter to valid.






        share|improve this answer






























          117














          You're probably in editing/insert mode. You need to type the following sequence :





          1. Esc, to quit edit mode and fallback to command mode ;


          2. :+w+q, start with a : (colon) then press w and finally q to write and quit (or just :w to write without quitting)

          3. then press Enter to valid.






          share|improve this answer




























            117












            117








            117







            You're probably in editing/insert mode. You need to type the following sequence :





            1. Esc, to quit edit mode and fallback to command mode ;


            2. :+w+q, start with a : (colon) then press w and finally q to write and quit (or just :w to write without quitting)

            3. then press Enter to valid.






            share|improve this answer















            You're probably in editing/insert mode. You need to type the following sequence :





            1. Esc, to quit edit mode and fallback to command mode ;


            2. :+w+q, start with a : (colon) then press w and finally q to write and quit (or just :w to write without quitting)

            3. then press Enter to valid.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 26 at 18:57









            Kulfy

            4,64151642




            4,64151642










            answered Feb 8 '13 at 15:08









            Édouard LopezÉdouard Lopez

            3,55342236




            3,55342236

























                17














                I usually press ESC and then hold Shift and press z twice. Just like you would like to type two capital Z letters in word editor :) That saves your document and closes your editor.






                share|improve this answer





















                • 3





                  Oh man, shift and double z, what was the design logic behind that I wonder, "what's the least intuitive command we can create?", ubuntu sometimes pisses me off like mad

                  – S..
                  May 25 '14 at 11:10






                • 4





                  @Sam, I just wanted to nitpick that vi has nothing in particular to do with ubuntu. Ubuntu was first released on 2004, while vi was created by Bill Joy around 1976, inspired by ed (dating back to 1971). This means that the shortcuts in vi predate those in almost any other still commonly used utility today. In a sort of coincidence, the first version of emacs, which has completely different weird shortcuts, was also released on 1976. Standardization efforts came much much later.

                  – yoniLavi
                  Nov 21 '14 at 2:00











                • Wow thanks for the info @yoniLavi , my points is still the same though, so hopefully standardization efforts keep advancing.. :)

                  – S..
                  Nov 21 '14 at 9:12











                • @Sam, vi keybindings are actually a lot more standard than you think; they're virtually ubiquitous. Practically any program can be made to emulate vi keybindings. Even the default Gmail keybindings are obviously (to a Vim user) based off of vi keybindings.

                  – Wildcard
                  Dec 21 '16 at 0:27











                • what about esc key does not work? Insert mode, just stopped.

                  – creator
                  Mar 10 '18 at 7:07
















                17














                I usually press ESC and then hold Shift and press z twice. Just like you would like to type two capital Z letters in word editor :) That saves your document and closes your editor.






                share|improve this answer





















                • 3





                  Oh man, shift and double z, what was the design logic behind that I wonder, "what's the least intuitive command we can create?", ubuntu sometimes pisses me off like mad

                  – S..
                  May 25 '14 at 11:10






                • 4





                  @Sam, I just wanted to nitpick that vi has nothing in particular to do with ubuntu. Ubuntu was first released on 2004, while vi was created by Bill Joy around 1976, inspired by ed (dating back to 1971). This means that the shortcuts in vi predate those in almost any other still commonly used utility today. In a sort of coincidence, the first version of emacs, which has completely different weird shortcuts, was also released on 1976. Standardization efforts came much much later.

                  – yoniLavi
                  Nov 21 '14 at 2:00











                • Wow thanks for the info @yoniLavi , my points is still the same though, so hopefully standardization efforts keep advancing.. :)

                  – S..
                  Nov 21 '14 at 9:12











                • @Sam, vi keybindings are actually a lot more standard than you think; they're virtually ubiquitous. Practically any program can be made to emulate vi keybindings. Even the default Gmail keybindings are obviously (to a Vim user) based off of vi keybindings.

                  – Wildcard
                  Dec 21 '16 at 0:27











                • what about esc key does not work? Insert mode, just stopped.

                  – creator
                  Mar 10 '18 at 7:07














                17












                17








                17







                I usually press ESC and then hold Shift and press z twice. Just like you would like to type two capital Z letters in word editor :) That saves your document and closes your editor.






                share|improve this answer















                I usually press ESC and then hold Shift and press z twice. Just like you would like to type two capital Z letters in word editor :) That saves your document and closes your editor.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 8 '13 at 18:01









                Kevin Bowen

                14.5k155970




                14.5k155970










                answered Feb 8 '13 at 16:05









                SephirothSephiroth

                28113




                28113








                • 3





                  Oh man, shift and double z, what was the design logic behind that I wonder, "what's the least intuitive command we can create?", ubuntu sometimes pisses me off like mad

                  – S..
                  May 25 '14 at 11:10






                • 4





                  @Sam, I just wanted to nitpick that vi has nothing in particular to do with ubuntu. Ubuntu was first released on 2004, while vi was created by Bill Joy around 1976, inspired by ed (dating back to 1971). This means that the shortcuts in vi predate those in almost any other still commonly used utility today. In a sort of coincidence, the first version of emacs, which has completely different weird shortcuts, was also released on 1976. Standardization efforts came much much later.

                  – yoniLavi
                  Nov 21 '14 at 2:00











                • Wow thanks for the info @yoniLavi , my points is still the same though, so hopefully standardization efforts keep advancing.. :)

                  – S..
                  Nov 21 '14 at 9:12











                • @Sam, vi keybindings are actually a lot more standard than you think; they're virtually ubiquitous. Practically any program can be made to emulate vi keybindings. Even the default Gmail keybindings are obviously (to a Vim user) based off of vi keybindings.

                  – Wildcard
                  Dec 21 '16 at 0:27











                • what about esc key does not work? Insert mode, just stopped.

                  – creator
                  Mar 10 '18 at 7:07














                • 3





                  Oh man, shift and double z, what was the design logic behind that I wonder, "what's the least intuitive command we can create?", ubuntu sometimes pisses me off like mad

                  – S..
                  May 25 '14 at 11:10






                • 4





                  @Sam, I just wanted to nitpick that vi has nothing in particular to do with ubuntu. Ubuntu was first released on 2004, while vi was created by Bill Joy around 1976, inspired by ed (dating back to 1971). This means that the shortcuts in vi predate those in almost any other still commonly used utility today. In a sort of coincidence, the first version of emacs, which has completely different weird shortcuts, was also released on 1976. Standardization efforts came much much later.

                  – yoniLavi
                  Nov 21 '14 at 2:00











                • Wow thanks for the info @yoniLavi , my points is still the same though, so hopefully standardization efforts keep advancing.. :)

                  – S..
                  Nov 21 '14 at 9:12











                • @Sam, vi keybindings are actually a lot more standard than you think; they're virtually ubiquitous. Practically any program can be made to emulate vi keybindings. Even the default Gmail keybindings are obviously (to a Vim user) based off of vi keybindings.

                  – Wildcard
                  Dec 21 '16 at 0:27











                • what about esc key does not work? Insert mode, just stopped.

                  – creator
                  Mar 10 '18 at 7:07








                3




                3





                Oh man, shift and double z, what was the design logic behind that I wonder, "what's the least intuitive command we can create?", ubuntu sometimes pisses me off like mad

                – S..
                May 25 '14 at 11:10





                Oh man, shift and double z, what was the design logic behind that I wonder, "what's the least intuitive command we can create?", ubuntu sometimes pisses me off like mad

                – S..
                May 25 '14 at 11:10




                4




                4





                @Sam, I just wanted to nitpick that vi has nothing in particular to do with ubuntu. Ubuntu was first released on 2004, while vi was created by Bill Joy around 1976, inspired by ed (dating back to 1971). This means that the shortcuts in vi predate those in almost any other still commonly used utility today. In a sort of coincidence, the first version of emacs, which has completely different weird shortcuts, was also released on 1976. Standardization efforts came much much later.

                – yoniLavi
                Nov 21 '14 at 2:00





                @Sam, I just wanted to nitpick that vi has nothing in particular to do with ubuntu. Ubuntu was first released on 2004, while vi was created by Bill Joy around 1976, inspired by ed (dating back to 1971). This means that the shortcuts in vi predate those in almost any other still commonly used utility today. In a sort of coincidence, the first version of emacs, which has completely different weird shortcuts, was also released on 1976. Standardization efforts came much much later.

                – yoniLavi
                Nov 21 '14 at 2:00













                Wow thanks for the info @yoniLavi , my points is still the same though, so hopefully standardization efforts keep advancing.. :)

                – S..
                Nov 21 '14 at 9:12





                Wow thanks for the info @yoniLavi , my points is still the same though, so hopefully standardization efforts keep advancing.. :)

                – S..
                Nov 21 '14 at 9:12













                @Sam, vi keybindings are actually a lot more standard than you think; they're virtually ubiquitous. Practically any program can be made to emulate vi keybindings. Even the default Gmail keybindings are obviously (to a Vim user) based off of vi keybindings.

                – Wildcard
                Dec 21 '16 at 0:27





                @Sam, vi keybindings are actually a lot more standard than you think; they're virtually ubiquitous. Practically any program can be made to emulate vi keybindings. Even the default Gmail keybindings are obviously (to a Vim user) based off of vi keybindings.

                – Wildcard
                Dec 21 '16 at 0:27













                what about esc key does not work? Insert mode, just stopped.

                – creator
                Mar 10 '18 at 7:07





                what about esc key does not work? Insert mode, just stopped.

                – creator
                Mar 10 '18 at 7:07











                3














                Check whether you have administrative (root) privileges to edit the file. use this command



                whoami


                If the result is not "root", then you are not supposed to edit the file.



                To login as root user, use the below command



                sudo su


                or



                su


                Edit the file,



                vi /etc/network/interfeces


                After the changes, save the file using




                1. Press Esc to change the mode


                2. :x to save and quit the file


                Thats all






                share|improve this answer






























                  3














                  Check whether you have administrative (root) privileges to edit the file. use this command



                  whoami


                  If the result is not "root", then you are not supposed to edit the file.



                  To login as root user, use the below command



                  sudo su


                  or



                  su


                  Edit the file,



                  vi /etc/network/interfeces


                  After the changes, save the file using




                  1. Press Esc to change the mode


                  2. :x to save and quit the file


                  Thats all






                  share|improve this answer




























                    3












                    3








                    3







                    Check whether you have administrative (root) privileges to edit the file. use this command



                    whoami


                    If the result is not "root", then you are not supposed to edit the file.



                    To login as root user, use the below command



                    sudo su


                    or



                    su


                    Edit the file,



                    vi /etc/network/interfeces


                    After the changes, save the file using




                    1. Press Esc to change the mode


                    2. :x to save and quit the file


                    Thats all






                    share|improve this answer















                    Check whether you have administrative (root) privileges to edit the file. use this command



                    whoami


                    If the result is not "root", then you are not supposed to edit the file.



                    To login as root user, use the below command



                    sudo su


                    or



                    su


                    Edit the file,



                    vi /etc/network/interfeces


                    After the changes, save the file using




                    1. Press Esc to change the mode


                    2. :x to save and quit the file


                    Thats all







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Feb 8 '13 at 16:04

























                    answered Feb 8 '13 at 15:59









                    SathishSathish

                    51136




                    51136























                        0














                        this question was answered a long time ago, but in case it comes up in search engines again, this link is a nice vim cheatsheet that you might want to bookmark if you use vim a lot.



                        By the way, You can use :wq to save and exit the file ( you should first press esc key to exit insert or replace mode and then press commands ) and use :q! to exit without saving.






                        share|improve this answer






























                          0














                          this question was answered a long time ago, but in case it comes up in search engines again, this link is a nice vim cheatsheet that you might want to bookmark if you use vim a lot.



                          By the way, You can use :wq to save and exit the file ( you should first press esc key to exit insert or replace mode and then press commands ) and use :q! to exit without saving.






                          share|improve this answer




























                            0












                            0








                            0







                            this question was answered a long time ago, but in case it comes up in search engines again, this link is a nice vim cheatsheet that you might want to bookmark if you use vim a lot.



                            By the way, You can use :wq to save and exit the file ( you should first press esc key to exit insert or replace mode and then press commands ) and use :q! to exit without saving.






                            share|improve this answer















                            this question was answered a long time ago, but in case it comes up in search engines again, this link is a nice vim cheatsheet that you might want to bookmark if you use vim a lot.



                            By the way, You can use :wq to save and exit the file ( you should first press esc key to exit insert or replace mode and then press commands ) and use :q! to exit without saving.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Oct 27 '18 at 9:54

























                            answered Aug 28 '17 at 9:56









                            razieh babaeerazieh babaee

                            1087




                            1087






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Ask Ubuntu!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f252760%2fhow-do-i-save-files-edited-with-vim%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                                Mangá

                                 ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕