I have often shared my Linux experience with you. Today I am going to share my Vi cheat sheet that has often saved me time in googling for a quick command.
Basic Vi commands
This is not a detailed tutorial to teach you each and every aspect of Vi editor. In fact, itโs not a tutorial at all. Itโs just a collection of basic Vi commands and their brief description for a quick reference.
Command | Description |
---|---|
:x | Save the file and quit |
:q! | Quit without saving the file |
i | Insert starting left of the cursor |
a | Append starting right of the cursor |
ESC | Exit insert/append mode |
arrows | Move cursor |
/text | Search string text (case sensitive) |
n | Search next occurrence of the searched item |
x | Delete character under the cursor |
dd | Delete line under the cursor |
u | Undo last change |
:0 | Beginning of the file |
:n | Go to line n |
G | End of the file |
^ | Beginning of the line |
$ | End of the line |
:set list | See special characters in the file |
yy | Copy the line into the buffer |
5yy | Copy 5 lines into the buffer |
p | Paste buffer after the current line |
You can download the above cheat sheet in a PDF format from the link below:
You can print it and keep it at your desk or just save it for offline use. And if you are interested, take this quiz and test the Vi knowledge you just learned.
Why did I create the Vi cheat sheet?
Several years ago, when I started working in the Linux terminal, the idea of using a command line editor horrified me. I had used desktop Linux before but it was my personal computer so I happily used GUI text editors like Gedit. But in the working environment, I was stuck with the command line and there was no scope of using a graphical editor.
I was forced to use Vi for basic edits in the files on remote Linux boxes and this is where I identified and started to admire the power of the command line editing tool Vi.
Since, at that time, I was new at Vi editor, I found myself baffled with it. The first time, I could not even come out of the file because I did not know how to close the Vi editor. No shame in accepting that I had to Google it.
So, I decided to list all the basic commands I frequently used for editing in Vi. This list or cheat sheet, as you may call it, helped me a lot in my early days with Vi. With time, I grew up with Vi and now I donโt even need to look at the Vi cheat sheet because I have the commands memorized by heart.
Why should you use Vi cheat sheet?
I can understand your situation if you are just getting started with Vi. Your favorite Ctrl+S doesnโt work for saving files. Ctrl+C and Ctrl+V were supposed to be the universal shortcut for copy and paste but it wonโt work in Vi universe.
Thousands of people use such cheat sheets for various programming languages and/or tools that give them a quick reference to commonly used steps/commands. Trust me, using cheat sheets is among the best practices advised to programmers.
This Vi cheat sheet will help you a lot if you are just starting with Vi or if you infrequently use the Vi editor (so you keep forgetting the commands). You can save it and use it for quick reference in the future, that too offline.
Do you like it?
So far, I have refrained from going into too much on the terminal side. How do you find this post? Do you want me to share more such cheat sheets and downloadable items? Your suggestions are welcomed.