Use Vim Editor Like a Pro

Use Vim Editor Like a Pro

Practical Guide On Vim Text Editor

You must have heard the many memes about exiting the Vim editor.

Memes are fun, but you don't need to be scared of the vim text editor. In this article, you will unleash the power to operate vim text editor like a pro.

What is vim

Vim (Vi Improved) is a UNIX text editor and it is an improved version of Bill Joy's Vi editor. Vim is a popular choice among programmers and system administrators for its power, flexibility, and portability. It is also used by many other users for tasks such as writing documentation, editing configuration files, and creating scripts.

Modes in Vim

Vim editor works in its mode. It has multiple modes available that have its own use cases. Today we'll talk about its most commonly used modes, which are:

  • Insert Mode

  • Normal or Command Mode

Insert Mode

Insert mode in Vim let you write whatever you want into the file. When you open a file or create a file using Vim editor, you enter into Vim's normal mode or you can say command mode. So to enter into insert mode, you have to press i button, and vim will be into insert mode and you can write anything you want.

Once you finish writing, just press the Esc button to enter command mode again and type :wq and hit enter to save the file and exit from the editor. A few common options are given below:

  • :wq - Save and exit from the editor.

  • :q! - Discard changes and exit from the editor.

  • :q - Exit only when there are no changes made, and give warning if any changes are done but do not exit.

  • :x - This is the short form for :wq

Command Mode

When you open a file or create a file using Vim editor, you enter into Vim's normal mode or you can say command mode. Command mode is a very special mode in the vim editor. You can change to any mode only when you are in command mode.

  • By pressing i you can enter into insert mode.

  • By pressing v you can enter into visual mode.

  • By pressing ctrl+v you can enter into visual block mode.

You can go back to command mode anytime by pressing the Esc button on your keyboard.

Some Useful Vim Commands

These commands which I am going to explain in this section, only work in command mode.

  • dd - This command will cut the entire line where your pointer is.

  • dw - This command will cut the word on the right side where your pointer is.

  • yy - It yanks (copies) the complete line where your pointer is.

  • p - It pastes the content which is cut or copied by dd, dw, or yy commands.

  • u - u stands for undo the change. It is like ctrl+z in our windows.

There are many other commands and use cases of vim editor which you can explore more from its documentation.

Bonus

If you want to explore more about vim within your terminal and practice it, vim tutor is a very helpful tool that has many lessons to learn about vim and its various modes and use cases.

You can invoke vim tutor by using vimtutor command in your CLI.

Conclusion

We have seen how to use Vim editor effectively and also its multiple commands that make the process faster of writing code, configs, templates, files, etc. in Vim editor.

Hope you liked this article. If you want more articles, tutorials, and guides like this then follow me on LinkedIn and subscribe to my newsletter.

Did you find this article valuable?

Support DevOps is Fun by becoming a sponsor. Any amount is appreciated!