How to save and quit a file in vi editor




















To switch to insert mode, press the i key. Now you can type text into a file. Press : colon to open the prompt bar in the bottom left corner of the window. Type x after the colon and hit Enter. This will save the changes and exit. Alternatively, a command that will also save a file and exit the text editor is:.

Type : colon. This will open the prompt bar in the bottom left corner of the window. Having learned the above commands, you can now proceed to learn advanced Vim commands from the links provided below:. In this article, we learned how to exit Vim text editor using simple commands. Do you have any questions to ask or any thoughts to share?

Please, use the feedback form below. TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint!

If you like what you are reading, please consider buying us a coffee or 2 as a token of appreciation. To go back to the Normal mode, just hit the Esc key on the keyboard. The syntax of Vi commands is quite easy to memorize. The default syntax to create a new text file is:.

To create a new text file named textfile. Note that if a file with the name textfile. Alternatively, you can launch the Vi editor in your terminal and then type :e textfile. The default command to save a text file in Vi is :w. Keep in mind that you can't use Vi commands while you're in the Insert Mode. Therefore, you will have to switch to Normal mode by pressing the Esc key. To save a file in Vi, enter into Normal mode by hitting Esc on your keyboard. Then, type :w and press Enter to save the file.

You can also save the file with a different name. Just pass the new file name with the :w command. This might feel like progress until you hit one of the arrow keys. If you do that, A, B, C, or D will appear as the only letter on an otherwise blank new line. At the top of the file. This is surprisingly easy when you know how. To enter Command mode, hit the Esc key. Nothing visible will happen. Hit it a few more times. These three characters should appear at the far left of the bottom line of the terminal.

Press the Enter key when you can see them:. In this command q is an abbreviation for quit. That might make you feel a little better. The exclamation point also instructs vi to not save any of the changes you may have made to the file.

You can do this with the following command:. To prevent you quitting and losing any changes you might wish to keep, vi is giving you the chance to save them. Just reissue the :q! Make sure you are entirely satisfied that you want your screen edits written to the file before you proceed. Type a colon, the letter w write and the letter q quit. Press the Enter key when you can see them in the lower left of the terminal:. Using vi is a bit like using a piano. Sitting down to it cold and trying to learn on the fly when the pressure is on you to get something edited is not the way to do it.

It makes as much sense as sitting down to a piano for the first time just as the curtain raises for your inaugural concert. Much of the power of vi comes from its many keystroke combinations that each perform a common editing task.



0コメント

  • 1000 / 1000