A few days ago I needed to use vi for a simple change in a single file. However, I am not using vi in normal situations since I prefer the usage of “nano“. Since I only needed to edit a few lines, all the command references I found on the Internet were much to overwhelmed, so I decided to write a really tiny vi tutorial which only shows the commands in order to edit a file and to close it afterwards. Here we go:
Open the file with vi textfile.
Go into the edit mode with “i” and edit the text. When you are finished, hit the Esc key to leave the edit mode. Type a colon followed by an “x” (appears at the bottom line) to quit vi with saving the changes. Thats it. Here is the sequence at a glance:
1 2 3 4 5 6 |
vi <textfile> i <Edit the text> <Esc> :x <Enter> |
If you want to quit vi without saving, type a “q!” instead of the “x”.
Here is a screenshot in which the last line shows the colon and the x:
For german people: If the keyboard setting of the Linux machine is not the german one, you’ll find the colon on shift+ö ;)
Other (much more detailled) lists of vi commands can be found here or here or here.
Featured image “Little Fellow” by Dmitry Baranovskiy is licensed under CC BY 2.0.
“:x”? Ich nehme immer “:wq” (write, quit). Again what learned ;o)