In this tutorial we will learn how to edit file in vi/Vim Editor - Save and quit in linux.
Contents of page >
- 1. How to edit file in vi/Vim Editor in linux >
- 2. Now, For exiting/quitting vi/Vim Editor without saving the file in linux>
- 2.1 SUMMARY, for exiting/quitting vi/Vim Editor without saving the file in linux>
- 3. For quitting vi/Vim Editor with - saving the file in linux>
- 3.1 For quitting vi/Vim Editor with saving the file (In shortest way) in linux>
- Summary
1. How to edit file in vi/Vim Editor in linux >
Let’s say you have to edit file MyFile.sh which is in diecrtoy /tmp/MyFile.sh
STEP1 : How to edit file in vi/Vim Editor >
Type
vi /tmp/MyFile.sh
Now, File will be opened in vi editor and look like this -
STEP2 : How to edit file in vi/Vim Editor >
Type “i” now you may insert in file. (You may also use Insert button of keyword to insert or replace)
After typing “i” editor will look like this -
STEP3 : How to edit file in vi/Vim Editor >
Now, you edit the file.
2. Now, For exiting/quitting vi/Vim Editor without saving the file in linux>
STEP1 : How to quit/exit vi/Vim Editor without saving the file >
Press Esc key on keyboard
Pressing Esc will remove
-- INSERT --
from editor and editor will look like this
STEP2 : How to quit/exit vi/Vim Editor without saving the file >
Type ’:’ (colon)
Typing ’:’ (colon) will put colon on lower left like this
STEP3 : How to quit/exit vi/Vim Editor without saving the file >
Type
‘q!’
OR, if you haven’t edited file you may type
STEP4 : How to quit/exit vi/Vim Editor without saving the file >
Press Enter
You will quit vi/Vim Editor without saving the file.
2.1 SUMMARY, for exiting/quitting vi/Vim Editor without saving the file in linux>
STEP1 : How to quit/exit vi/Vim Editor without saving the file >
Press Esc key on keyboard
STEP2 : How to quit/exit vi/Vim Editor without saving the file >
Type ’:’ (colon)
STEP3 : How to quit/exit vi/Vim Editor without saving the file >
Type
‘q!’
STEP4 : How to quit/exit vi/Vim Editor without saving the file >
Press Enter
You will quit vi/Vim Editor without saving the file.
3. For quitting vi/Vim Editor with - saving the file in linux>
STEP1 : How to quit/exit vi/Vim Editor - saving the file >
Then press Esc key on keyboard
STEP2 : How to quit/exit vi/Vim Editor - saving the file >
Then type ’:’ (colon)
STEP3 : How to quit/exit vi/Vim Editor - saving the file >
Type
‘wq!’
STEP4 : How to quit/exit vi/Vim Editor - saving the file >
Press Enter
You will quit vi/Vim Editor saving the file.
3.1 For quitting vi/Vim Editor with saving the file (In shortest way) in linux>
STEP1 : How to quit/exit vi/Vim Editor - saving the file (In shortest way) >
Press Esc key on keyboard
STEP2 : How to quit/exit vi/Vim Editor - saving the file (In shortest way) >
You may also simply type
‘ZZ’
You will quit vi/Vim Editor saving the file.
Summary -
In this linux tutorial we learned How to edit file in vi/Vim Editor in linux. For exiting/quitting vi/Vim Editor without saving the file. For quitting vi/Vim Editor with - saving the file.
Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.
RELATED LINKS>
Quitting vi/Vim Editor with - saving the file in linux
Exiting/ quitting vi/Vim Editor without saving the file
vi error - E37: No write since last change (add ! to override)
bash: ./yourScriptFile.sh: Permission denied Linux solved
Labels:
Linux