Table of contents
No headings in the article.
Using VI Editor for a beginner can be difficult, like writing content in the file and especially exiting it. Here is a blog that can help you as a beginner to use VI Editor.
Let us create a file example.txt.
Now, suppose you want to write something in this file. One way is to simply use the 'cat > example.txt ' command.
While this works well, it is a very basic form and offers no additional features and is not feasible when dealing with a large amount of text or code. For that, we have several text editors available, but VI appears to be the most popular one.
Use the command ' vi <name_of_file> ' to open the VI Editor.
Now you are inside the VI Editor.
VI Editor has two modes of operation.
Command mode
Insert mode
When you open a file in VI Editor, by default you are in command mode. In this mode, you can issue commands to the editor such as to copy and paste lines or delete a line or a word or navigate b/w lines.
But in Command mode you cannot write content to the file. To write content to the file you must switch to the Insert mode. And to do so, type 'i' in lowercase. Now you are in the insert mode. To switch back to the command mode press the 'esc' key.
Let us see what operations are available in the command mode.
You can move around the editor using the arrow keys.
To delete a character press 'x' in lowercase.
To delete a line, type 'dd'
To copy a line, type 'yy' and to paste it type 'p'
Typing in the colon ':' will take you to the prompt where you can type in commands.
To save the changes made to the file and write the file to disc using the ':w!' command.
To discard any unsaved changes made to the file and quit the editor, type the ':q!' command.
To save changes and quit, type in the ':wq!' command.
So, that was a short blog on VI Editor. If you like the blog, then don't forget to share it with your connections. My content is all about Open Source, DevOps, various CNCF tools and Cloud.