21
How to learn Vim with examples
When I first tried to learn Vim, it was not easy at all.I couldn’t have total control that I had with other IDE such as VSCode.
Then, I repeated several times with desire to learn it but failed to maintain what I learnt later. But, I had to use it to deploy websites and I could learn it really.
I just remembered what an experienced developer told before.
“You learn something better when you have to work with real projects”
I had to use it to solve what was difficult for me with Vim to really learn it.
While using it for real projects, I did find its benefits.
It is already installed almost on every system. You don’t have to install it for a new dev environment.
It doesn’t need much HD and works very well with less resources.
It is better at solving simple problems when you are already accustomed to use it.
- Where to begin?
- List of minimal Vim commands
- Conclusion
I think this website can be very useful for beginners.
First, it is very interactive and you can control your learning phase and back to previous process easily.
Second, there are even practice pages for you to use what you learnt.
I have repeated this several times before I had to start the real project.
You can visit it first or after reading List of Vim commands below.
Then, you can verify what you learnt with $vimtutor
command.
It is very helpful to start to learn Vim with it. I hope you to go on until lesson 2 at least and hope you already know how to navigate and edit texts.
If you followed them well, you already know Vim sufficiently to use at real work. But, I want to give you minimal Vim commands to remember.
Photo by Kaitlyn Baker
When you open files with $vim test.txt
Vim starts with editor mode
. You can use I
to start with insert mode
and back to editor mode
again with [Esc]
or ctrl + [
commands.
You can move cursors with these when you are in editor mode. It will take sometime to be familiar with them.
⬅ h to left,
⬇ j to down
⬆ k to up
➡ l to right
You can also use ⬅ ⬇⬆ ➡ on keyboard instead whether you are in Editor Mode or not.
Writing what you want with Vim, you need to save it and quit from the vim.
To do that, you need to use these.
$vim test.txt
- push [i] on keyboard to switch from normal mode to insert mode.
- Write something.
- push [Esc] to back to normal mode.
- push [shift + :] + wq(:wq) to write and quit
Repeat this process until you become familiar with it.
When you want to write more contents for existing files, you will start with the end of file.
You can start it with ‘G’ and “gg”* to back to the beginning of the file.
You can combine this with ‘d’ command to delete every lines with gg ➡ dG and it will clear file for you and you don’t have to make a new one.
They are used when it is not in editor mode(You can stop editor mode with ESC).
- ‘x’ to delete a word below the cursor
- I already showed use case of ‘d’ above. It can be combined with other keys.
For example, you can test them.
- “dw” to delete a word
- “d$” to delete a line after current cursor postion
- You can also use ‘C’ instead to the same as “d$” \
- “cc” to remove a line and to use Insert Mode
- ‘r’ to replace a character below the current cursor position
When you use delete relevant commands they are saved to the clipboard.
You can use ‘p’ to paste it and later you can paste again with either ‘p’ or ‘.’ to repeat previous command.
You can use ‘u’ for undo when something went wrong and redo with [ctrl + shift + r].
Photo by Jordan Hile
You can use ‘/’ in [Normal Mode] to find some words and you can use ’n’ to move to the next and ’N’ to the previous.
You can also combine numbers with them. You can test it locally.
It is useful to correct missing trailing , or ; etc when you edit a file.
- :w to write, which means save the file and :q to quit without saving
- :wq to write, save and quit (You will use this normally.)
These were the commands for beginners I thought useful.
You will need to use the editor mode to write texts and the normal mode mostly.
Be calm and verify well which mode you are and think before you type something if something went wrong. You can always use ‘u’ in the normal mode to undo something.
Photo by Al x
I hope you complete the post well. I want to tell you that you don’t need a lot of time to start to use Vim.
Just practice first and use it inside your own project. In time, You will find that you are already using it well.
Thanks.
21