How To Save A File In Vim/Vi? - LinuxTect
Có thể bạn quan tâm
Vim is a useful command-line text editor. As a featureful text editor, Vim/Vi provides different ways and commands in order to save a file. In this tutorial, we examine how to save the file with the same name or a different name or exit after saving the file.
Save File with write Command
The write command is used to save or write changes into the current file. In order to use the write command first, the normal mode should be enabled.
- Press ESC key to change normal mode.
- Type :write in order to save file and then press Enter.
The Vim uses the shortcuts regularly and the :w can be used as a shortcut for the :write command.
- Press ESC key to change normal mode.
- Type :w in order to save file and then press Enter.
When the write or save operation is completed some information will be provided about save under Vim.
- sample.txt is the file name which is saved.
- 17L is the line numbers which are saved.
- 3122C is the characters count which are saved.
Save File with Different Name
By default, the save operation will save the changes into the current file with the same file name. But you can save the changes into a new file and continue with this file by providing the file name to the :write or :w commands. In the following example, we will save the file as a new file with the name mysample.txt.
- Press ESC key to change normal mode.
- Type :write mysample.txt in order to save file and then press Enter.
Or as a short form.
- Press ESC key to change normal mode.
- Type :w mysample.txt in order to save file and then press Enter.
Save File and Quit
Vim provides different commands in order to save files and exit. This is very useful for fast operation. We will provide the wq commands which are short forms of the write and quit.
- Press ESC key to change normal mode.
- Type :wq in order to save file and then press Enter.
An alternative way is using the x command according to the wq command.
- Press ESC key to change normal mode.
- Type 😡 in order to save file and then press Enter.
Quit Without Saving File
You can make different changes in a file and then want to not save these changes and exit from the file without saving changes. You can use the quit! or q! commands which will quit or exit from the Vim without saving changes.
- Press ESC key to change normal mode.
- Type :quit! in order to save file and then press Enter.
Or
- Press ESC key to change normal mode.
- Type :q! in order to save file and then press Enter.
Từ khóa » Vi In Linux Save
-
An Introduction To The Vi Editor | Enable Sysadmin - Red Hat
-
How To: Vi / Vim Save And Quit The Editor Command - NixCraft
-
How To Save A File In Vi / Vim Text Editor - NixCraft
-
How To Save A File In Vi / Vim Editor & Quit - PhoenixNAP
-
How To Save A File In Vim / Vi And Quit The Editor - Linuxize
-
Using Vi? Here's How To Open A File Then Save And Quit - MakeUseOf
-
How To Save A File In Vi / Vim Editor In Linux - Tecmint
-
Saving Changes And Quitting Vi
-
How To Save & Quit In VIM Or VI | OSXDaily
-
Saving Files And Quitting Vi
-
VI Editor With Commands In Linux/Unix Tutorial - Guru99
-
How To Save A File In Vi / Vim And Quit Editor - TecAdmin
-
How To Exit (quit) Linux Vi Editor With Or Without Saving Changes Step ...
-
How To Save A File In Linux After Using The Vi Command