Edit files with vim

In certain system configurations, we need to use a text editor which doesn’t have a Graphical User Interface (GUI). In those configurations, vim is something we can rely on. Graphical based editor are easy to comprehend. So, those editors can be anyone’s preferred choice. But, once you understand different functions of vim then, you would realize how easy and efficient it can be working with vim. In this article, we would cover only the basics. Mainly, we would see how to edit files with vim.

vim basically has got two modes – command and input. vim always opens a file in command mode. Thereafter, we need to enter a command to make changes to the file. But, when switching back from input mode to command mode, press Esc key.

Edit files with vim

Let’s say we have a text file – abc. Use vim to open it –

vim ~/Downloads/abc

It will open the file in command mode. We can use following commands to add text or initiate the input mode –

a – add command. To input the text to the right of the cursor. And, the other one is –

i – insert command. To input the text to the left of the cursor.

Thereafter, we need to get back to the command mode once we finish editing/writing the file. As discussed earlier, use Esc key to get back to command mode. Now, we need to provide command to either save and exit or to just simply exit from the command mode.

:w – this saves our work but, we can still continue editing the files,

:q – if we haven’t made any changes to the file, then it is used to quit,

:wq – this we would use pretty frequently, it serves both purpose – save the file and quit,

:q! – sometimes, we have made changes to the file but, for some reason we don’t want to save the work and leave the file as it is. In that case, we need to forcefully quit the file. So, in those circumstances use this option.

In conclusion, we saw how to open a file with vim. And, we discussed how to use various command options.

Similar Posts