IMP NOTE: avoid reading this post if you are looking for advance vi features or unix vi editor commands. Below is to enable fresher groups to be comfortable with Unix VI editor.
UNIX vi editor commands were the first biggest hurdle for me to get interest in UNIX, I was refraining to cultivate interest in UNIX initially. Just because I was not convinced to remember many commands to work in text editor in today’s time (like vi editor). Moreover because of UNIX server settings I was not even able to use FTP tools also like filezilla and WinScp.
As you might also have noticed, I also saw many people having vi cheat sheet print outs marked in there cubicle to remember UNIX vi editor commands. Oh my god, That was my first constraint to start with UNIX. Believe me, It really took time for me to buy this idea that “vi editor is not so complicated as it is generally get showed in vi cheat sheet”
One can do all text editing just by remembering 4-5 UNIX vi editor commands. and rest of the things can be managed by little hacks.
5 Unix Vi Editor commands (Enough for new users to run the show )
[ESC] most widely used, Safest bet at any point of time. In simple words, it is a GURU MANTRA for vi editor. It lets you to play safe. [More technically]- [ESC] changes the vi MODE. [ESC] : From INSERT MODE to COMMAND MODE]: Means cursor movement man. Take cursor anywhere you want. Escape means freedom in vi editor (I really talk crazy sometime?)
[ESC] i: From COMMAND MODE to INSERT MODE.] And this means that no changes in text will take place and you can do cursor movement without worries move around for anything to come out you better use esc ,otherwise vi editor will show you colors.
[ESC] – Move left up right down : Escape arrow keys
[ESC] i – insert any character
[ESC] x – Delete one character
[ESC] dd – – Delete whole line
Now you can manage few more things with below hacks
TO WRITE AT END OF A LINE: Why to remember any command for it, Browse till second last character, write last character, Now you write what you want to write and at last.Now you do [ESC]x to remove last character of your line. This way you have inserted text at last of line.
TO WRITE END OF A FILE: In fact you don’t have to remember any command for this also. Scroll till second last line , copy paste last line , after that insert or write your text. Now delete last line with [ESC]dd.
Few more very basic Unix Vi Editor commands
Exiting a file: it’s not something you have to remember I believe, it’s something which will be the first steps to get your hands off in vi editor, very basic in nature
[ESC]:q! exit and ignore any changes
[ESC]:wq exit with save
Below are not basic commands, little important if you are ok to extend commands to remember from 4 to 6 !!!!!. Below are helpful while debugging shell scripts , you can easily locate error text or line numbers with issues referred in script log files.
[ESC]:? Search_Text [ESC]:/Search_Text
[ESC]: Set Number to display line number against each line –
See above to know How to open a file in vi editor with line numbers? I believe that above unix vi editor commands will help you reduce fear for vi editor and let you jump straight into it. Still if you feel that something very basic needs to be included, let me know , I will include it in my post with you name and picture(if provided). Post a comment and I will get back to your email id.